mirror of
https://github.com/zebrajr/opencv.git
synced 2026-01-15 12:15:17 +00:00
Update and expand erosion / dilation tutorial
- Add python explanation for erosion and dilation - Add java explanation for erosion and dilation - Restructure and reword specific sections
This commit is contained in:
@@ -34,6 +34,7 @@ public class MorphologyDemo1 {
|
||||
private JFrame frame;
|
||||
private JLabel imgLabel;
|
||||
|
||||
//! [constructor]
|
||||
public MorphologyDemo1(String[] args) {
|
||||
String imagePath = args.length > 0 ? args[0] : "../data/LinuxLogo.jpg";
|
||||
matImgSrc = Imgcodecs.imread(imagePath);
|
||||
@@ -54,7 +55,9 @@ public class MorphologyDemo1 {
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
//! [constructor]
|
||||
|
||||
//! [components]
|
||||
private void addComponentsToPane(Container pane, Image img) {
|
||||
if (!(pane.getLayout() instanceof BorderLayout)) {
|
||||
pane.add(new JLabel("Container doesn't use BorderLayout!"));
|
||||
@@ -114,21 +117,31 @@ public class MorphologyDemo1 {
|
||||
imgLabel = new JLabel(new ImageIcon(img));
|
||||
pane.add(imgLabel, BorderLayout.CENTER);
|
||||
}
|
||||
//! [components]
|
||||
|
||||
//! [update]
|
||||
private void update() {
|
||||
//! [kernel]
|
||||
Mat element = Imgproc.getStructuringElement(elementType, new Size(2 * kernelSize + 1, 2 * kernelSize + 1),
|
||||
new Point(kernelSize, kernelSize));
|
||||
//! [kernel]
|
||||
|
||||
if (doErosion) {
|
||||
//! [erosion]
|
||||
Imgproc.erode(matImgSrc, matImgDst, element);
|
||||
//! [erosion]
|
||||
} else {
|
||||
//! [dilation]
|
||||
Imgproc.dilate(matImgSrc, matImgDst, element);
|
||||
//! [dilation]
|
||||
}
|
||||
Image img = HighGui.toBufferedImage(matImgDst);
|
||||
imgLabel.setIcon(new ImageIcon(img));
|
||||
frame.repaint();
|
||||
}
|
||||
//! [update]
|
||||
|
||||
//! [main]
|
||||
public static void main(String[] args) {
|
||||
// Load the native OpenCV library
|
||||
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
||||
@@ -142,4 +155,5 @@ public class MorphologyDemo1 {
|
||||
}
|
||||
});
|
||||
}
|
||||
//! [main]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user