0

my objective here is simply to detect the seat no matter where's the image is positioned. To make things even simpler this is the only image that will be shown on the screen but the position of the image may change. User may move it right, left, up down and maybe show part of the image.

I read this thread that shows how to 'Brute-force' the image to detect a subset of an image but when I tried it - it took my 100+ seconds to detect it (really long time, though I'm not looking for real-time) and also, I think my challenge is simpler.

Q: What should be my approach here? I've never tried anything with image processing and ready to go this path (if its applicable here).

Thanks!

this is the image that will be shown on the screen (might be shown only part of it, say user moved it all the way to the right and it shows only the rear wheal with the seat)

enter image description here

subset image is always like this:

enter image description here

Community
  • 1
  • 1
adhg
  • 10,437
  • 12
  • 58
  • 94
  • 1
    Does your robot have access to the screen contents, or does it use a video camera to capture an imperfect copy of it? If it's the former, you don't need any fancy "minimum error" matching algorithm -- just do a brute-force comparison for exact pixel equality. – j_random_hacker May 04 '14 at 02:00
  • 2
    Emphasizing what @j_random_hacker said: The effort that is required here mainly depends on how predicable the image will be. If the image is *exactly* the *same*, then this task is rather easy and can be solved very efficiently. But if this may refer to a photo that is taken under different light conditons, with a different background or taken under a different viewing angle, this task may become arbitrarily hard - and even impossible. Even for a human. Considering that the light might simply be switched off ;-) – Marco13 May 04 '14 at 02:04
  • 3
    If you are only concerned with translation, rather than rotation and scale, a template matching technique based on [phase correlation](http://en.wikipedia.org/wiki/Phase_correlation) would be the most efficient way to go. Libraries like OpenCV [offer this functionality](http://docs.opencv.org/doc/tutorials/imgproc/histograms/template_matching/template_matching.html). – Roger Rowland May 04 '14 at 07:24

1 Answers1

1

given javaCV and openCV this snippet code does the job:

public class RunTest1
{   
  public static void main(String args[])
  { 

    IplImage src = cvLoadImage("C:\\Users\\Nespresso\\Desktop\\cervelo.jpg",0);
    IplImage tmp = cvLoadImage("C:\\Users\\Nespresso\\Desktop\\subImage.jpg",0);    

    IplImage result = cvCreateImage(cvSize(src.width()-tmp.width()+1, src.height()-tmp.height()+1), IPL_DEPTH_32F, 1);
    cvZero(result);

    //Match Template Function from OpenCV
    cvMatchTemplate(src, tmp, result, CV_TM_CCORR_NORMED);

    double[] min_val = new double[2];
    double[] max_val = new double[2];

    CvPoint minLoc = new CvPoint();
    CvPoint maxLoc = new CvPoint();

    //Get the Max or Min Correlation Value      
    cvMinMaxLoc(result, min_val, max_val, minLoc, maxLoc, null);

    System.out.println(Arrays.toString(min_val));
    System.out.println(Arrays.toString(max_val));

    CvPoint point = new CvPoint();
    point.x(maxLoc.x()+tmp.width());
    point.y(maxLoc.y()+tmp.height());

    cvRectangle(src, maxLoc, point, CvScalar.WHITE, 2, 8, 0);//Draw a Rectangle for Matched Region

    cvShowImage("Lena Image", src);
    cvWaitKey(0);
    cvReleaseImage(src);
    cvReleaseImage(tmp);
    cvReleaseImage(result);

}    

}

enter image description here

adhg
  • 10,437
  • 12
  • 58
  • 94