使用open cv实时在python中进行Circle检测

时间:2016-02-29 06:37:44

标签: python opencv

我正在使用运动检测来处理这个项目,然后我遇到了识别物体的需要 但我在这个所有的图像处理事物上都是noob

你能告诉我python opencv的VideoCapture()函数中的圆检测源代码(主要是houghcircles)

P.S。请勿在需要的图像中提供圆形检测代码,以便在我目前通过网络摄像头拍摄的视频中检测到它

1 个答案:

答案 0 :(得分:0)

视频中圆圈检测的C ++代码

 #include<opencv2/core/core.hpp>
    #include<opencv2/highgui/highgui.hpp>
    #include<opencv2/imgproc/imgproc.hpp>
    #include<vector>
    #include<iostream>
    using namespace std;
    using namespace cv;
    int main()
    {
        Mat img;
        Mat thresh;
        VideoCapture cap(0);
        vector<Vec3f>circles;   
        for(;;)
            {
                cap>>img;
                cvtColor(img,img,CV_BGR2GRAY);
                GaussianBlur(img,img,Size(5,5),2,2);//smoothing reduces false positives
                threshold(img,thresh,130,255,THRESH_BINARY);
                HoughCircles(thresh,circles,CV_HOUGH_GRADIENT,2,img.rows/5,200,100);
                cvtColor(img,img,CV_GRAY2BGR);
                for(int i=0;i<(int)circles.size();i++)
                {
                    Point center=Point((int)circles[i][0],(int)circles[i][1]);          
                    int radius=(int)circles[i][2];              
                    circle(img,center,radius,Scalar(255,255,0),4);
                }
                imshow("img",img);
                imshow("thresh",thresh);
                char c=waitKey(10);
                if(c=='b' || c=='B'){
                    break;  
                }
            }
        return 0;
    }
相关问题