2014-11-22 71 views
0

我在Eclipse Luna中使用OpenCV(Java)。我遇到了drawContours方法的问题。 该代码没有错误,但是当我去运行它的图像加载,但没有可见的countours。
图片类:OpenCV drawContours问题

public static void main(String[] args){ 
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 
    Mat m = Highgui.imread("C:/Users/MyName/Desktop/shapes.png", Highgui.CV_LOAD_IMAGE_COLOR); 
    Mat hsv = new Mat(); 
    Mat mask = new Mat(); 
    Mat dilmask = new Mat(); 
    Mat fin = new Mat(); 
    Scalar color = new Scalar(239, 117, 94); 
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 
    Imgproc.cvtColor(m, hsv, Imgproc.COLOR_RGB2HSV); 
    new LoadImage("C:/Users/MyName/Desktop/shapes2.png", m); 
    Scalar lowerThreshold = new Scalar (120, 100, 100); 
    Scalar upperThreshold = new Scalar (179, 255, 255); 
    Core.inRange (hsv, lowerThreshold , upperThreshold, mask); 
    Imgproc.dilate (mask, dilmask, new Mat()); 
    Imgproc.findContours(dilmask, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); 
    //Imgproc.drawContours(fin, contours, -1, color, 0); 
    for (int contourIdx=0; contourIdx < contours.size(); contourIdx++) 
     { 
     if(contours.size()>10) // Minimum size allowed for consideration 
     { 
      Imgproc.drawContours (fin, contours, contourIdx, color, 3); 
     } 
     } 
    //Highgui.imwrite("C:/Users/MyName/Desktop/shapes2.png", fin); 



} 

}

的LoadImage类(并不重要,只是进行帧显示图像):

public class LoadImage extends JFrame{ 
public LoadImage(String imgStr,Mat m) 
{ 
Highgui.imwrite(imgStr,m); 
JFrame frame = new JFrame("My GUI"); 
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

frame.setResizable(true); 
frame.setLocationRelativeTo(null); 

// Inserts the image icon 
ImageIcon image = new ImageIcon(imgStr); 
frame.setSize(image.getIconWidth()+10,image.getIconHeight()+35); 
// Draw the Image data into the BufferedImage 
JLabel label1 = new JLabel(" ", image, JLabel.CENTER); 
frame.getContentPane().add(label1); 

frame.validate(); 
frame.setVisible(true);} 



} 

Input image

这可能是一个简单的修复,但我找不到任何关于它的事情。

回答

-2

我知道答案,用的值玩法:

Scalar lowerThreshold = new Scalar (h1, s1, v1); 
Scalar upperThreshold = new Scalar (h2, s2, v2); 
+0

“我知道答案”是不是一个很好的答案。 – stuXnet 2014-12-17 12:57:56