Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java opencv中的Hough圆变换未检测到任何圆_Java_Opencv - Fatal编程技术网

Java opencv中的Hough圆变换未检测到任何圆

Java opencv中的Hough圆变换未检测到任何圆,java,opencv,Java,Opencv,我正在编写一个程序,使用Houghcircles()方法检测图像中特定颜色的圆 在这句话之后打印圆垫给了我这样的信息,即使我运行程序来获得完美圆的图像: Mat [ 0*0*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x894140, dataAddr=0x0 ] 由于行数和列数均为零,因此该方法显然不支持循环 以下是完整的代码: public static void main(String args[]) { System.loa

我正在编写一个程序,使用Houghcircles()方法检测图像中特定颜色的圆

在这句话之后打印圆垫给了我这样的信息,即使我运行程序来获得完美圆的图像:

Mat [ 0*0*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x894140, dataAddr=0x0 ]
由于行数和列数均为零,因此该方法显然不支持循环

以下是完整的代码:

public static void main(String args[]) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    Mat srcImg = imread("img.png");

    Mat thresholdedImg = new Mat(srcImg.rows(),srcImg.cols(),CvType.CV_8UC1);

    byte black[] = {0,0,0};
    byte w = getUnsignedByte(255);
    byte white[] = {w,w,w};

    double requiredBlue[] = {225.0,105.0,65.0}; // BGR values of shade to be detected


    for(int i=0;i<srcImg.rows();i++) {
        for(int j=0;j<srcImg.cols();j++) {
            double currentPixel[] = srcImg.get(i,j);    
            if(currentPixel[0]==requiredBlue[0] && currentPixel[1]==requiredBlue[1] && currentPixel[2]==requiredBlue[2])
                thresholdedImg.put(i, j, black);
            else
                thresholdedImg.put(i, j, white);
        }
    }

    Mat circles = new Mat(srcImg.rows(),srcImg.cols(),CvType.CV_8UC1);

    Imgproc.HoughCircles(thresholdedImg,circles,Imgproc.CV_HOUGH_GRADIENT,1d,100,200,100,1,100);

    displayImage(Mat2BufferedImage(circles));
}
publicstaticvoidmain(字符串参数[]){
System.loadLibrary(Core.NATIVE\u LIBRARY\u NAME);
Mat srcImg=imread(“img.png”);
Mat thresholdedImg=new Mat(srcImg.rows(),srcImg.cols(),CvType.CV_8UC1);
字节黑色[]={0,0,0};
字节w=getUnsignedByte(255);
字节白色[]={w,w,w};
双所需蓝色[]={225.0105.0,65.0};//待检测阴影的BGR值

对于(int i=0;iDid您是否检查ThresholdIDimg?它是否真的包含圆圈?您是否可以在此处发布ThresholdIDimg?这篇文章可能会有所帮助:这实际上是我为该程序引用的文章之一。这对我当前的问题没有帮助。我编辑了我的文章以包含ThresholdIDimg。圆圈似乎太小,您是否尝试过使用较大的图像?或者您需要降低hough变换圆检测器的阈值。我的意思是“param_2=100*:中心检测的阈值”。降低阈值有效。谢谢!podt示例图像
public static void main(String args[]) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    Mat srcImg = imread("img.png");

    Mat thresholdedImg = new Mat(srcImg.rows(),srcImg.cols(),CvType.CV_8UC1);

    byte black[] = {0,0,0};
    byte w = getUnsignedByte(255);
    byte white[] = {w,w,w};

    double requiredBlue[] = {225.0,105.0,65.0}; // BGR values of shade to be detected


    for(int i=0;i<srcImg.rows();i++) {
        for(int j=0;j<srcImg.cols();j++) {
            double currentPixel[] = srcImg.get(i,j);    
            if(currentPixel[0]==requiredBlue[0] && currentPixel[1]==requiredBlue[1] && currentPixel[2]==requiredBlue[2])
                thresholdedImg.put(i, j, black);
            else
                thresholdedImg.put(i, j, white);
        }
    }

    Mat circles = new Mat(srcImg.rows(),srcImg.cols(),CvType.CV_8UC1);

    Imgproc.HoughCircles(thresholdedImg,circles,Imgproc.CV_HOUGH_GRADIENT,1d,100,200,100,1,100);

    displayImage(Mat2BufferedImage(circles));
}