expand the perimeter of a circle

asked 2013-01-02 01:25:37 -0500

cms gravatar image

updated 2013-01-02 01:27:55 -0500

Hi everyone ! I'm using opencv 2.4.2 and visual studio 2010 software for my program. The code is used to program a USB webcam to detect the cooking stoves (circle). Although the edge detection is not stable (keep blinking), but it managed to draw a green line (detection) when i point my webcam onto the screen (where's the picture of the stove is).picture of the stove . My question is how do i extend the detection of the perimeter of the stove ? I have to extend the circle detection of the last layer of the stove outward.

> #include "stdafx.h"

#include <stdio.h>
#include <cv.h>
#include <ml.h>
#include <cxcore.h>
#include <highgui.h>
#include <math.h>


int main(int argc, char* argv[])
{
    CvCapture *capture = 0;
    IplImage *img = 0;
    int key = 0;
    CvFont font;
    cvInitFont(&font, CV_FONT_HERSHEY_PLAIN,1.0,1.0,0,1,CV_AA);

capture = cvCaptureFromCAM(0);

if (!capture) 
{
    fprintf(stderr, "Cannot open initialize webcam!\n");
    return 1;
}

//create a wondow in which the captured images will be presented
cvNamedWindow("result", CV_WINDOW_AUTOSIZE);

img = cvQueryFrame(capture); 
if(!img)
    exit(1);
IplImage *gray = cvCreateImage(cvGetSize(img), 8,1);
CvMemStorage* storage = cvCreateMemStorage(0);

while(key != 'q') {
    img = cvQueryFrame(capture);
    if(!img) break;

    cvCvtColor(img, gray, CV_BGR2GRAY);
    cvSmooth( gray, gray, CV_GAUSSIAN, 9, 9 );
    CvSeq* circles = cvHoughCircles( gray, storage, CV_HOUGH_GRADIENT, 1, gray->height/8, 200, 100, 0, 0 );
     int i;
     for( i = 0; i < circles->total; i++ )
         {
             float* p = (float*)cvGetSeqElem( circles, i );
             cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(0,255,0), 2, 8, 0 );
             cvLine (img, cvPoint(cvRound(p[0]+40),cvRound(p[1])), cvPoint(cvRound(p[0]),cvRound(p[1])), CV_RGB(0,255,0), 1, CV_AA,0);
             cvLine (img, cvPoint(cvRound(p[0]),cvRound(p[1]+40)), cvPoint(cvRound(p[0]),cvRound(p[1])), CV_RGB(0,255,0), 1, CV_AA,0);
             cvLine (img, cvPoint(cvRound(p[0]-40),cvRound(p[1])), cvPoint(cvRound(p[0]),cvRound(p[1])), CV_RGB(0,255,0), 1, CV_AA,0);
             cvLine (img, cvPoint(cvRound(p[0]),cvRound(p[1]-40)), cvPoint(cvRound(p[0]),cvRound(p[1])), CV_RGB(0,255,0), 1, CV_AA,0);
             cvPutText(img, "Safe",cvPoint(cvRound(p[0]+45),cvRound(p[1]+45)), &font, CV_RGB(0,0,255));
        }
      cvShowImage( "result", img ); 
      key = cvWaitKey( 10 );
      if(key == 27) break;  

}
//release the device capture housekeeping
cvReleaseCapture( &capture ); 
cvDestroyWindow( "result" ); 
return 0;

}

edit retag flag offensive close merge delete

Comments

So you need to detect the outer circle. Have you tried with different threshold for the HoughCircle ?.

Haris gravatar imageHaris ( 2013-01-02 04:22:47 -0500 )edit

sorry for the super late reply. yes i have try the different method but still cant work .

cms gravatar imagecms ( 2013-01-07 20:01:54 -0500 )edit
Haris gravatar imageHaris ( 2013-01-07 22:54:49 -0500 )edit