Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

hough circle detection problem

MY CODE IS :

i want to detect outer circle is it possible ?

video is here

//  SYDNIA DYNAMICS 2015

#include <iostream>
#include <stdio.h>
#include <vector>
#include <thread>
#include <opencv2/opencv.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/nonfree.hpp"

using namespace cv;

Mat src, src_gray;
Mat dst, detected_edges;

int threshold_value = 11;
int threshold_type = 0;;
int  max_value = 255;
int  max_type = 4;

const char * window_name = "CCC";
string trackbar_type = "Tbin";
string trackbar_value = "Value";

int main(int argc, char *argv[])
{
    VideoCapture cap;

    cap = VideoCapture("D:/SYDNIA/1.AVI");

    if (!cap.isOpened())  // if not success, exit program
    {
        std::cout << " !! --->> camera problem " << std::endl;
        return -1;
    }
    namedWindow(window_name);
    cvMoveWindow(window_name, 5, 5);

    int MAX = 130;
    createTrackbar("MAX", window_name, &MAX, 300);
    int MIN = 100;
    createTrackbar("MIN", window_name, &MIN, 300);
    int BLACKLEVEL = 47;

    for (;;) {

        if (!cap.read(src))
        {
            std::cout << "GRAB FAILURE" << std::endl;
            exit(EXIT_FAILURE);
        }

        cvtColor(src, src_gray, CV_RGB2GRAY);

        blur(src_gray, src_gray, Size(15, 15));

        threshold(src_gray, dst, 11, 255, 0); //tareshold
        vector<Vec3f> circles;
        HoughCircles(dst, circles, CV_HOUGH_GRADIENT, 1, dst.rows, 20, 7, MIN, MAX);


        string status = "";
        for (size_t i = 0; i < circles.size(); i++)
        {

            Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));

            bool ok = false;

            int r = src.at<Vec3b>(center.y, center.x)[0];
            int g = src.at<Vec3b>(center.y, center.x)[1];
            int b = src.at<Vec3b>(center.y, center.x)[2];


            if ((r<BLACKLEVEL) && (g<BLACKLEVEL) && (b<BLACKLEVEL))ok = true;


            if (ok)
            {
                int radius = cvRound(circles[0][2]);
                circle(src, center, 2, Scalar(30, 255, 140), -1, 3, 0);
                circle(src, center, radius, Scalar(30, 255, 0), 3, 8, 0);
                status = "2";
                break;
            }
            else
            {
                status = "0";
            }

        }

        imshow(window_name, src);
        imshow("HSV", dst);

        if (waitKey(1) == 27)break;

    }


    return 0;

}

source picture :

image description

code output center:

image description

is it possible to make it :

image description