Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top