Ask Your Question

nhat.truong's profile - activity

2014-12-03 01:24:53 -0600 asked a question How to recognize the image that have a circle ?

Hi everyone, After using InrangeS() function to seperate the green area from an image, I get a binary image contain white and black area. In white area, I don't know how to recognize that they're not circle or they're circle. I'm very grateful if everyone help me to solve this problem. I'll enclose the image I get after using Hough transform for everyone :) Thanks a lotC:\fakepath\image.png

2014-09-14 06:12:17 -0600 asked a question Smoothing image after using Inrange() function

Hi everybody ! I used Inrange() function to detect tennis ball from webcam (this ball is green), after I used this function I got an binary image that is very rough. Here is my code : void morphOps(Mat &thresh) {

        Mat erodeElement = getStructuringElement( MORPH_RECT,Size2i (2,2));
        Mat dilateElement = getStructuringElement( MORPH_RECT,Size2i (20,20));
        erode(thresh,thresh,erodeElement);
        erode(thresh,thresh,erodeElement);
        dilate(thresh,thresh,dilateElement);
        dilate(thresh,thresh,dilateElement);
        return;
    }

void main() { VideoCapture capture(0); Mat src,dst,hsv; int red,grn,blu,red1,grn1,blu1 =0; namedWindow("Window"); namedWindow("Window1"); createTrackbar("red","Window",&red,255); createTrackbar("green","Window",&grn,255); createTrackbar("blue","Window",&blu,255); createTrackbar("red1","Window1",&red1,255); createTrackbar("green1","Window1",&grn1,255); createTrackbar("blue1","Window1",&blu1,255);

while(true)
{

    capture >> src;
    cvtColor(src,hsv,COLOR_BGR2HSV);
    Scalar lower(red,grn,blu);
    Scalar upper(red1,grn1,blu1);
    inRange(hsv,lower,upper,dst);

            //morphOps(dst);

            imshow("Input Image",hsv);
            imshow("Output Image",dst);
            char c= waitKey(10);
            if(c==27) break;
}

This is Input image after transforming to HSV color C:\fakepath\input.png and the result C:\fakepath\clutter.png Can everyone help me to filter and smooth this image ? And finally there is only this ball on black background. This result is created after I choose the argument for Scalar is : lower(41,44,49) upper(91,255,255) ! Have a great day !!

2014-09-13 11:42:36 -0600 commented answer How to create trackbar

sorry this is my mother language :) It means the image after finding out right circle

2014-09-13 11:07:55 -0600 commented answer How to create trackbar

I think I must use the trackbar change event to solve this problem but I don't know how to use this trackbar event. Can you help me about this problem ? Have a great day

2014-09-13 11:05:30 -0600 commented answer How to create trackbar

@berak I used trackbar to find out the suitable argument for Houghcircle function and then draw right circle cover my object, but everytime I change value of trackbar then I can't change the circle was drew in the previous time. Here is my code : createTrackbar("min_dist_px","Window",&min_dist_px,255); createTrackbar("canny_threshold","Window",&canny_threshold,255); createTrackbar("acc_threshold","Window",&acc_threshold,255); createTrackbar("min_radius","Window",&min_radius,255); createTrackbar("max_dist_px","Window",&max_radius,255);

        vector<Vec3f> circles;

        HoughCircles(dst,circles,CV_HOUGH_GRADIENT,
            1, // dp
            min_dist_px, // min_dist_px
            canny_threshold, // higher canny
            acc_threshold, // acc threshold
            min_radius, // min radius
            max_radius);
2014-09-13 10:32:11 -0600 commented answer I can't paint the circle into image after using Hough transform :(

@FooBar I attached this image in my answer.

2014-09-13 04:54:56 -0600 commented answer How to create trackbar

@berak thank you

2014-09-13 03:52:32 -0600 asked a question How to create trackbar

Hi everybody ! I want to create a trackbar to change the value of argument in inRange() function. I realize that everytime I change Scalar in this function and debug, it takes many times. I want to create a trackbar to change Scalar when I'm debugging . Can everyone help me about this problem ? Thanks very much

2014-09-12 11:15:24 -0600 answered a question I can't paint the circle into image after using Hough transform :(

@FooBar I got a good result when I used your code, but when I used webcam to track the tennis ball, I got a bad result. There were many wrong circle drew arround this ball but no right circle drew cover this ball. Here is my code : capture >> col; cvtColor(col.clone(),src,CV_BGR2GRAY); equalizeHist(src,src); GaussianBlur( src, src, Size(9, 9), 2, 2 ); if(src.empty()) { cout<< "can't load file from webcam" <<endl; }<="" p="">

        int canny_threshold = 200;

        vector<Vec3f> circles;
        HoughCircles(src,circles,CV_HOUGH_GRADIENT,
            1, // dp
            50, // min_dist_px
            canny_threshold, // higher canny
            20, // acc threshold
            0, // min radius
            100); // max radius

            for(int i=0;i<circles.size(); i++)
            {
            Point center(cvRound(circles[i][0]),cvRound(circles[i][1]));
            int radius = cvRound(circles[i][2]);
            circle(col,center,radius,Scalar(0,0,255),2,8,0);
            }

        imshow("Window1",col);
        char c = waitKey(33);
        if(c==27) break;
    }

Can you help me about this problem ? I will attach the bad result I got when I run my program at here C:\fakepath\Untitled2.png The original Image C:\fakepath\ball.jpg Have a great day !

2014-09-12 08:22:35 -0600 asked a question I can't detect and draw the circle cover the tennis ball using webcam

Hi everybody ! I used webcam to detect and draw the circle cover the ball that was got from webcam using Hough transform, but I couldn't draw right circle cover this ball and there were many wrong circles were painted. Here is my code : VideoCapture capture(0); Mat src,col; while(true) { capture >> col; cvtColor(col.clone(),src,CV_BGR2GRAY); GaussianBlur( src, src, Size(9, 9), 2, 2 ); if(src.empty()) { cout<< "can't load file from webcam" <<endl; }<="" p="">

        int canny_threshold = 200;

        vector<Vec3f> circles;
        HoughCircles(src,circles,CV_HOUGH_GRADIENT,
            1, // dp
            50, // min_dist_px
            canny_threshold, // higher canny
            20, // acc threshold
            0, // min radius
            0); // max radius

            for(int i=0;i<circles.size(); i++)
            {
            Point center(cvRound(circles[i][0]),cvRound(circles[i][1]));
            int radius = cvRound(circles[i][2]);
            circle(col,center,radius,Scalar(0,0,255),2,8,0);
            }

        imshow("Window1",col);
        char c = waitKey(33);
        if(c==27) break;
    }

Can everyone help me about this problem ? I will attach the error window that contain many wrong circles I got when I debug at here C:\fakepath\Untitled2.png Have a great day !

2014-09-11 00:15:21 -0600 commented answer I can't paint the circle into image after using Hough transform :(

I want to write value of "radius" and "center" in Window but I get a mistake that I don't know why. Here is my code : cout <<"The radius of circle" << radius << endl; cout <<"The center of circle" << center <<endl; Can you help me ? @FooBar

2014-09-10 23:36:17 -0600 commented answer I can't paint the circle into image after using Hough transform :(

@FooBar thanks very much...but can you indicate me how to recognize "canny_threshold" and "acc threshold" ? I think maximum value of threshold is 255

2014-09-10 11:26:39 -0600 commented question I can't paint the circle into image after using Hough transform :(

Those params are (0,0) because I don't know the radius of ball, so I put (0,0) into those params to search automatically all circles in image

2014-09-10 11:00:32 -0600 commented question Find Contour

thanks everyone so much

2014-09-10 10:56:22 -0600 asked a question I can't paint the circle into image after using Hough transform :(

Hi everybody ! I used Hough transform to detect circle and then I will paint the circle into my input image ( tennis ball ) depend on those parameter that Hough issued ( center,radius ). Here is my code :

            Mat src1 = imread("banhtennis.jpg");
    Mat src2 = src1.clone();
    Mat gray,canny;

    cvtColor(src1,gray,CV_BGR2GRAY);
    Canny(gray,canny,20,30,3,false);
    vector<Vec3f> circles;
    HoughCircles(canny,circles,CV_HOUGH_GRADIENT,1,100,30,20,0,0);
    for(int i=0;i<circles.size();i++)
    {
        Point center(cvRound(circles[i][0]),cvRound(circles[i][1]));
        int radius = cvRound(circles[i][2]);
        circle(src2,center,radius,Scalar(0,0,255),2,8,0);
    }
            imshow("Anh sau khi tim thay duong tron",src2);

The result I received after running my program was many red circles that were painted on the input image but not the circle I need. I need the circle cover my ball in this image. Can everyone help me about this problem ? I will attach this image at here C:\fakepath\banhtennis.jpg Thanks very much ^^

2014-09-09 11:17:17 -0600 asked a question Find Contour

Hi Everybody ! I used the function cvFindContours() to find contour of my image. Here is my code :

int main() { IplImage *src = cvLoadImage("meo.jpg"); CvMemStorage *storage = cvCreateMemStorage(0); cvMemStorageAlloc(storage,100); CvSeq *firstcontour = NULL; cvFindContours(src,storage,&firstcontour,sizeof(CvChain),CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE); cvShowImage("Anh Goc",src);

cvWaitKey(0);
cvReleaseImage(&src); 
cvDestroyAllWindows();
return 1;

}

When I debug, my program will terminate. Can everyone help me about this problem ? I don't know why ! I will attach the image that I used in this code. Thanks a lotC:\fakepath\meo.jpg

2014-09-05 05:04:21 -0600 commented answer How to transfer Image from webcam to gray image ?

thank you ! Have a great day

2014-09-05 04:18:36 -0600 commented answer How to transfer Image from webcam to gray image ?

@StevenPuttemans Thanks so much :D but I still can't know why my program didn't run. I think " IplImage " is like with " Mat " . Can you tell me about this problem ?

2014-09-05 03:24:53 -0600 commented question How to transfer Image from webcam to gray image ?

@jamesnzt I tried following your method but this program still suspended. When I debug, it appears the notification : Unhandled exception at 0x76b12eec in OpenCV3.exe: Microsoft C++ exception: cv::Exception at memory location 0x0062f94c.. Can you help me ? Thanks so much :D

2014-09-04 22:41:31 -0600 commented question How to transfer Image from webcam to gray image ?

@StevenPuttemans I added line " char c = cvWaitKey(33) " but my program still suspend. I don't know why ?

2014-09-04 08:48:22 -0600 asked a question How to transfer Image from webcam to gray image ?

Hi everybody1 I obtain an image from my webcam and then transfer it to a gray image to process. Here is my code:

int main()
{
    CvCapture *capture = cvCreateCameraCapture(0);
    IplImage *src = cvCreateImage(cvSize(50,50),8,1);
    IplImage *src1 = cvCreateImage(cvSize(50,50),8,3);
    while (true)
    {
        src1 = cvQueryFrame(capture);
        cvCvtColor(src1,src,CV_BGR2GRAY); 
        char c = cvWaitKey(33);
        if(c == 27)
        {
            break;
        }

        cvShowImage("TestWebCam",src1);
        cvShowImage("TestWebCam2",src);


    }

When I compile my program it's no error but when I Run this program then It will terminate. I don't no Why but I think the error happen at line " cvCvtColor(src1,src,CV_BGR2GRAY) " because if I delete this line then I can obtain image from webcam normally. Everyone can help me correct this error ! Have a great day :D

2014-08-29 11:25:22 -0600 received badge  Editor (source)
2014-08-29 11:23:28 -0600 asked a question How to regconize tennis ball by Webcam Logitech

Hi everybody, I'm working with my thesis about Image Processing. I don't know how to regconize tennis ball by Webcam. There are 2 problem i must handle : color and shape. This ball is green and circle. How can I regconize 2 features of this ball ? Give me some methods or some algorithm to handle these problems ! Thanks Everyone so much. Have a great day :D