0

I have image as follows:

enter image description here

I want to detect 5 dials for processing. Hough circles is detecting all other irrelevant circles. to solve this i created a plain image and generated absolute difference with this one. It gave this image:

enter image description here

I drew box around it and final image is:

enter image description here

My code is as follows:

Mat img1 = imread(image_path1, COLOR_BGR2GRAY); 
Mat img2 = imread(image_path2, COLOR_BGR2GRAY);

cv::Mat diffImage;
cv::absdiff(img2, img1, diffImage);

cv::Mat foregroundMask = cv::Mat::zeros(diffImage.rows, diffImage.cols, CV_8UC3);

float threshold = 30.0f;
float dist;

for(int j=0; j<diffImage.rows; ++j)
{
    for(int i=0; i<diffImage.cols; ++i)
    {
        cv::Vec3b pix = diffImage.at<cv::Vec3b>(j,i);

        dist = (pix[0]*pix[0] + pix[1]*pix[1] + pix[2]*pix[2]);
        dist = sqrt(dist);

        if(dist>threshold)
        {
            foregroundMask.at<unsigned char>(j,i) = 255;
        }
    }
}

cvtColor(diffImage,diffImage,COLOR_BGR2GRAY);

Mat1b img = diffImage.clone();

// Binarize image
Mat1b bin = img > 70;

// Find non-black points
vector<Point> points;
findNonZero(bin, points);

// Get bounding rect
Rect box = boundingRect(points);

// Draw (in color)
rectangle(img1, box, Scalar(0,255,0), 3);

// Show
imshow("Result", img1);

Now the issue is i cant compare plain image with anyother iamge of different sizes. Any pointer to right direction will be very helpful.

Regards, Saghir A. Khatr

Edit My plain image is as follows

enter image description here

I want to create a standard sample plain image which can be used with any image to detect that portion...

Community
  • 1
  • 1
Saghir A. Khatri
  • 3,429
  • 6
  • 45
  • 76
  • basically i have nothing to worry about except 5 dials in image. which i am doing furthur process – Saghir A. Khatri Mar 14 '16 at 08:00
  • Ok, then try any rigid registration sample code. In the fixed image ,,plaid,, keep numbers and dials. Mask the plates only. – mainactual Mar 14 '16 at 08:12
  • @mainactual plates means the hands?? – Saghir A. Khatri Mar 14 '16 at 08:17
  • I mean that your registration metric should be calculated inside the white plates only. But not against your plain but hands-only-removed-plain-image. – mainactual Mar 14 '16 at 08:26
  • 1
    At best, you need to perform registration with rotation and scaling. Unless you have a good registration algorithm handy, I'd recommend to customize a generalized Hough procedure so that it detects five touching circles in a row. This should be much more discriminant than the search for single circles. –  Mar 14 '16 at 08:49
  • Can we see the output of Hough ? –  Mar 14 '16 at 08:51
  • @YvesDaoust sadly i removed output of houghCircles :( sorry – Saghir A. Khatri Mar 14 '16 at 08:58

0 Answers0