ChitraPathak / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

cvGoodFeaturesToTrack issue #137

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Basically the code runs correctly, but the output is not what should be 
expected.

No matter what image I load, the number of corners detected is always 1.

I am using the latest release of JavaCV on Windows 7 Professional.
So far, I've been using OpenCV with no problems.

Here is my sample code; any comment would be well appreciated.

import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;

public class imgProc {

    public static void main(String[] args) throws Exception {

        String filePath = "C:/temp/testimg.jpg";

        //load image in img
        IplImage img = cvLoadImage(filePath);

        int max_corners = 500;
        CvSize img_sz = cvGetSize(img);

        IplImage gray = cvCreateImage(img_sz, IPL_DEPTH_8U, 1);
        IplImage cpy = img.clone();

        cvCvtColor(img, gray, CV_BGR2GRAY);

        IplImage eig_img = cvCreateImage(img_sz, IPL_DEPTH_32F, 1);
        IplImage tmp_img = cvCreateImage(img_sz, IPL_DEPTH_32F, 1);

        int[] corner_count = { max_corners };
        CvPoint2D32f corners = new CvPoint2D32f(max_corners);
        double qltyLevel = 0.05;
        double minDist = 5.0;
        CvArr mask = null;
        int blkSize = 3;
        int useHarris = 1;
        double k = 0.04;

        cvGoodFeaturesToTrack(gray, eig_img, tmp_img, corners, corner_count, qltyLevel, minDist, mask, blkSize, useHarris, k);

        System.out.println("No. of corners detected:" + corner_count.length);       
    }
}

Original issue reported on code.google.com by vanina1...@gmail.com on 9 Dec 2011 at 2:59

GoogleCodeExporter commented 9 years ago
And what does corner_count[0] gives?

Original comment by samuel.a...@gmail.com on 9 Dec 2011 at 3:06

GoogleCodeExporter commented 9 years ago
corner_count[0] gives 131.

Original comment by vanina1...@gmail.com on 9 Dec 2011 at 3:10

GoogleCodeExporter commented 9 years ago
Plus corners.position(i) gives very large values for coordinates:

run:
(1129644032, 1140719616)
(1145634816, 1139736576)
(1145618432, 1139474432)
(1145716736, 1140490240)
(1131479040, 1140555776)
(1145880576, 1140457472)
(1129906176, 1140621312)
(1146404864, 1138458624)...

Original comment by vanina1...@gmail.com on 9 Dec 2011 at 3:45

GoogleCodeExporter commented 9 years ago
And what if you reset corners to corners.position(0) before passing it to 
cvGoodFeaturesToTrack()?

Original comment by samuel.a...@gmail.com on 9 Dec 2011 at 4:01

GoogleCodeExporter commented 9 years ago
no change in the generated values.

Original comment by vanina1...@gmail.com on 9 Dec 2011 at 4:07

GoogleCodeExporter commented 9 years ago
Your code above plus the following works just fine here:
        System.out.println("No. of corners detected:" + corner_count[0]);
        corners.capacity(corner_count[0]);
        for (int i = 0; i < corner_count[0]; i++) {
            System.out.println(corners.position(i));
        }
If you still have problems, let me know, otherwise please post your future 
questions on the mailing list if possible, thank you

Original comment by samuel.a...@gmail.com on 9 Dec 2011 at 4:40

GoogleCodeExporter commented 9 years ago
I'm sorry the values I was posting was those of the CvPoint I created for
each position(i), and I hadn't carried out the conversion well.
It's all good now.

:) Thank you.

Original comment by vanina1...@gmail.com on 9 Dec 2011 at 4:56