2

我正在编写用于在 OpenCV 中检测具有 HSV 颜色空间的蓝色圆形对象的代码,程序还可以在对象的帮助下移动鼠标指针。我在我的代码中实现了 HoughCircles 函数,但它没有执行。这是代码:

 #include "cv.h"
 #include "highgui.h"
 #include <iostream>
 #include <windows.h>

using namespace cv;
using namespace std;



int main()
{

VideoCapture cap(0);
if(!cap.isOpened()) return -1;

Mat vd,copy,imgScribble;
namedWindow("Video",1);
namedWindow("Capture",1);
int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);
int ww = cap.get(CV_CAP_PROP_FRAME_WIDTH);
int wh = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
double adjw = width/ww;
double adjh = height/wh;
int h = 640 * adjh;
int w = 320 * adjw;

for(;;)
{   
    cap>>vd;


    GaussianBlur( vd, vd, Size(9, 9), 2, 2 );



    cvtColor(vd,copy,CV_RGB2HSV);
    Mat thresh;

    inRange(copy,Scalar(0,200,0),Scalar(13,255, 255),thresh);
    flip(thresh,thresh,1);
    Moments mom = moments(thresh);
    double moment10 = mom.m10;
    double moment01 = mom.m01;
    double area = mom.m00;
    static int posX = 0;
    static int posY = 0;

    int lastX = posX;
    int lastY = posY;

    posX = moment10/area;
    posY = moment01/area;
    h = posX * 2.134375;
    w = posY * 2.4;
    vector<Vec3f> circles;
    HoughCircles(vd,circles,CV_HOUGH_GRADIENT,2,vd.rows/4,100,100,0,0);
    if(area >= 1000)
    {
    SetCursorPos(h,w);
    }

    cout<<height<<"x"<<width<<endl;
    cout<<h<<"xx"<<w<<endl;

    imshow("Capture",vd);   
    imshow("Video",thresh);


    if(waitKey(30) >= 0) 
    break;
}
cap.release();
return 0;
 }

请帮我找到 HoughCircles 的解决方案?提前致谢。

4

0 回答 0