Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/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
Colors 识别opencv中检测到的圆的颜色_Colors_Opencv_Geometry - Fatal编程技术网

Colors 识别opencv中检测到的圆的颜色

Colors 识别opencv中检测到的圆的颜色,colors,opencv,geometry,Colors,Opencv,Geometry,您将如何使用opencv中的cvHoughcircles来识别每个检测到的圆的颜色? 我已经添加了代码,显示了我当前正在尝试的但是我得到了一个错误:IVIETest1.xe中的0x75 8D9617未处理的异常:微软C++异常:CV::内存位置0x00 19ED4< /P>异常 #include <stdio.h> #include <cv.h> #include <highgui.h> #include <math.h> int main(in

您将如何使用opencv中的cvHoughcircles来识别每个检测到的圆的颜色? 我已经添加了代码,显示了我当前正在尝试的但是我得到了一个错误:IVIETest1.xe中的0x75 8D9617未处理的异常:微软C++异常:CV::内存位置0x00 19ED4< /P>异常
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <math.h>

int main(int argc, char** argv)
{
    //load image from directory
    IplImage* img = cvLoadImage("C:\\Users\\Nathan\\Desktop\\SnookerPic.png");


    IplImage* gray = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
    CvMemStorage* storage = cvCreateMemStorage(0);

    //covert to grayscale
    cvCvtColor(img, gray, CV_BGR2GRAY);

    // This is done so as to prevent a lot of false circles from being detected
    cvSmooth(gray, gray, CV_GAUSSIAN, 7, 7);

    IplImage* canny = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
    IplImage* rgbcanny = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
    cvCanny(gray, canny, 50, 100, 3);

    //detect circles
    CvSeq* circles = cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT, 1, 35.0, 75, 60,0,0);
    cvCvtColor(canny, rgbcanny, CV_GRAY2BGR);

    //draw all detected circles
    for (int i = 0; i < circles->total; i++)
    {
         // round the floats to an int
         float* p = (float*)cvGetSeqElem(circles, i);
         cv::Point center(cvRound(p[0]), cvRound(p[1]));
         int radius = cvRound(p[2]);
cvScalar c;
         c = cvGet2D(img, center.x, center.y);//colour of circle

         // draw the circle center
         cvCircle(img, center, 3, CV_RGB(0,255,0), -1, 8, 0 );

         // draw the circle outline
         cvCircle(img, center, radius+1, CV_RGB(0,0,255), 2, 8, 0 );

         //display coordinates
         printf("x: %d y: %d r: %d\n",center.x,center.y, radius);
    }

    //create window
    cvNamedWindow("circles", 1);
    cvNamedWindow("SnookerImage", 1);
    //show image in window
    cvShowImage("circles", rgbcanny);
    cvShowImage("SnookerImage", img);

    cvSaveImage("out.png", rgbcanny);
    cvWaitKey(0);

    return 0;
}
#包括
#包括
#包括
#包括
int main(int argc,字符**argv)
{
//从目录中加载图像
IplImage*img=cvLoadImage(“C:\\Users\\Nathan\\Desktop\\SnookerPic.png”);
IplImage*gray=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
CvMemStorage*storage=cvCreateMemStorage(0);
//隐到灰度
CVT颜色(img、灰色、CV_bgr2灰色);
//这样做是为了防止检测到大量假圆
cvSmooth(灰色、灰色、CV_高斯、7、7);
IplImage*canny=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
IplImage*rgbcanny=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
cvCanny(灰色,canny,50,100,3);
//检测圆
CvSeq*圆=cvHoughCircles(灰色,存储,CV_-HOUGH_梯度,1,35.0,75,60,0,0);
CVTColor(canny、rgbcanny、CV_GRAY2BGR);
//绘制所有检测到的圆
对于(int i=0;itotal;i++)
{
//将浮点数四舍五入为整数
float*p=(float*)cvGetSeqElem(圆,i);
cv::点中心(cvRound(p[0]),cvRound(p[1]);
int radius=cvRound(p[2]);
cvc;
c=cvGet2D(img,center.x,center.y);//圆的颜色
//画圆心
CV圆(img,中心,3,CV_RGB(0255,0),-1,8,0);
//画圆的轮廓
CV圆(img,中心,半径+1,CV_RGB(0,0255),2,8,0);
//显示坐标
printf(“x:%d y:%d r:%d\n”,中心x,中心y,半径);
}
//创建窗口
cvNamedWindow(“圆圈”,1);
cvNamedWindow(“斯诺克时代”,1);
//在窗口中显示图像
cvShowImage(“圆”,rgbcanny);
cvShowImage(“斯诺克时代”,img);
cvSaveImage(“out.png”,rgbcanny);
cvWaitKey(0);
返回0;
}

您试图获取颜色的当前圆的坐标似乎超出范围。在尝试获取颜色之前,您应该检查每个点是否在图像范围内(例如center.x>0&¢er.x0&¢er.y您可以在这里找到一个相同的问题:谢谢。我添加了cvScalar代码,现在内存位置出现错误??你能发布你的代码和错误吗?也许我们可以提供更多这样的帮助。我已经发布了我的代码和错误。我希望你能帮助我,我看到的唯一错误是cvScalar c,应该是cvScalar c。但这会导致编译错误。您应该调试它并查看它在哪里崩溃。如果你把图片上传到某个服务器上并传递链接,也许我以后可以看一看。谢谢。我用整数改变了坐标,它运行了,所以一定是这样。我不知道为什么圆心会超出范围,因为我在绘制检测到的圆后得到的图像显示了图像中的圆心