Ask Your Question

Sylvain's profile - activity

2020-11-16 15:02:39 -0600 received badge  Good Question (source)
2019-09-11 05:06:22 -0600 received badge  Famous Question (source)
2018-09-30 23:46:26 -0600 received badge  Notable Question (source)
2018-05-07 20:20:48 -0600 received badge  Notable Question (source)
2018-03-18 16:12:55 -0600 received badge  Popular Question (source)
2017-10-26 17:49:09 -0600 received badge  Popular Question (source)
2016-10-17 20:48:32 -0600 received badge  Popular Question (source)
2016-01-04 23:13:21 -0600 received badge  Notable Question (source)
2014-12-09 13:49:14 -0600 marked best answer opencv_traincascade and opencv_createsample on windows

I need to use a cascade classifier. I've read these guide which is prety clear.

I use Windows 7 I've already use OpeNCV for 2 or 3 project in java, i've install it with this guide, with the prebuild libraries

But when i'm trying those command, windows can't find them... i guess it's an install problem, but i can't find what's wrong. Sorry... noob problem...

2014-12-09 13:46:57 -0600 marked best answer Image is empty

Hi,

i'm totally new with OpenCV and i'm starting with the Java version.

I'm trying some basics. The first part in the java tutorial was a success. I'm trying the Lena's Face detection. But i've a problem when I'm loading the file :

Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());
System.out.println(image.toString());

Console return :

Mat [ 0*0*CV_8UC1, isCont=false, isSubmat=false, nativeObj=0x1ffed20, dataAddr=0x0 ]

I'm sure the path to the picture is good, if i change it i've a segmentation fault.

If someone have a idea...

2014-11-12 10:23:03 -0600 received badge  Famous Question (source)
2014-11-05 07:51:56 -0600 received badge  Popular Question (source)
2014-02-04 10:18:27 -0600 received badge  Notable Question (source)
2013-11-07 23:06:01 -0600 received badge  Nice Question (source)
2013-10-16 14:26:39 -0600 received badge  Popular Question (source)
2013-07-09 02:37:53 -0600 marked best answer The homography tutorial in java

EDIT : main problem solved (see in comments) ! But i now have a problem with perspectiveTransform()...

OpenCV Error: Assertion failed (scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F)) in unknown function, file ......\src\opencv\modules\core\src\matmul.cpp, line 1926


Original post

Hi,

i'm trying to redo this tutorial in Java... but it doesn't work. The findHomography function didn't work, and the error message isn't very clear for me :

OpenCV Error: Assertion failed (npoints >= 0 && points2.checkVector(2) == npoints && points1.type() == points2.type()) in unknown function, file ..\..\..\src\opencv\modules\calib3d\src\fundam.cpp, line 1074

I realy hope someone will be able to help me... i'm a novice with OpenCV

Here is my code, sorry it's a bit long :

CODE UPDATED

class FindObject {
  public void run(String pathObject, String pathScene, String pathResult) {

System.out.println("\nRunning FindObject");

Mat img_object = Highgui.imread("D:/workspaceSeirich/HelloCV/".concat(pathObject), 0); //0 = CV_LOAD_IMAGE_GRAYSCALE
Mat img_scene = Highgui.imread("D:/workspaceSeirich/HelloCV/".concat(pathScene), 0);

FeatureDetector detector = FeatureDetector.create(4); //4 = SURF 

MatOfKeyPoint keypoints_object = new MatOfKeyPoint();
MatOfKeyPoint keypoints_scene  = new MatOfKeyPoint();

detector.detect(img_object, keypoints_object);
detector.detect(img_scene, keypoints_scene);

DescriptorExtractor extractor = DescriptorExtractor.create(2); //2 = SURF;

Mat descriptor_object = new Mat();
Mat descriptor_scene = new Mat() ;

extractor.compute(img_object, keypoints_object, descriptor_object);
extractor.compute(img_scene, keypoints_scene, descriptor_scene);

DescriptorMatcher matcher = DescriptorMatcher.create(1); // 1 = FLANNBASED
MatOfDMatch matches = new MatOfDMatch();

matcher.match(descriptor_object, descriptor_scene, matches);
List<DMatch> matchesList = matches.toList();

Double max_dist = 0.0;
Double min_dist = 100.0;

for(int i = 0; i < descriptor_object.rows(); i++){
    Double dist = (double) matchesList.get(i).distance;
    if(dist < min_dist) min_dist = dist;
    if(dist > max_dist) max_dist = dist;
}

System.out.println("-- Max dist : " + max_dist);
System.out.println("-- Min dist : " + min_dist);    

LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
MatOfDMatch gm = new MatOfDMatch();

for(int i = 0; i < descriptor_object.rows(); i++){
    if(matchesList.get(i).distance < 3*min_dist){
        good_matches.addLast(matchesList.get(i));
    }
}

gm.fromList(good_matches);

Mat img_matches = new Mat();
Features2d.drawMatches(
        img_object,
        keypoints_object, 
        img_scene,
        keypoints_scene, 
        gm, 
        img_matches, 
        new Scalar(255,0,0), 
        new Scalar(0,0,255), 
        new MatOfByte(), 
        2);

LinkedList<Point> objList = new LinkedList<Point>();
LinkedList<Point> sceneList = new LinkedList<Point>();

List<KeyPoint> keypoints_objectList = keypoints_object.toList();
List<KeyPoint> keypoints_sceneList = keypoints_scene.toList();

for(int i = 0; i<good_matches.size(); i++){
    objList.addLast(keypoints_objectList.get(good_matches.get(i).queryIdx).pt);
    sceneList.addLast(keypoints_sceneList.get(good_matches.get(i).trainIdx).pt);
}

MatOfPoint2f obj = new MatOfPoint2f();
obj.fromList(objList);

MatOfPoint2f scene = new MatOfPoint2f();
scene.fromList(sceneList);

Mat H = Calib3d.findHomography(obj, scene);

LinkedList<Point> cornerList = new LinkedList<Point>();
cornerList.add(new Point(0,0));
cornerList.add(new Point(img_object.cols(),0));
cornerList.add(new Point(img_object.cols(),img_object.rows()));
cornerList.add(new Point(0,img_object.rows()));

MatOfPoint obj_corners = new MatOfPoint();
obj_corners.fromList(cornerList);

MatOfPoint scene_corners = new MatOfPoint();

//ERROR HERE :
//OpenCV Error: Assertion failed (scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F)) in unknown function, file ..\..\..\src\opencv\modules\core\src\matmul.cpp, line 1926
Core.perspectiveTransform(obj_corners, scene_corners, H);

//Draw the lines... later, when the homography will work
/*
Core.line(img_matches, new Point(), new Point(), new ...
(more)
2013-05-06 10:29:06 -0600 commented answer Java : How to use Crosscheck ?

Thanx a lot, I'll try this tomorrow but that's look nice :)

2013-05-06 02:51:49 -0600 asked a question Java : How to use Crosscheck ?

Hi !

I've follow the tutorial "object detection in a scene" (http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html#feature-homography) and redo the same thing in java... and that's work pretty well. But I still have a question.

If I want to search an object which is not in the scene, I still have a (false) result. If I've well understand, using the crosscheck option for the brute-force matcher can help to deal with that. But I can't find how to use crosscheck, I can't find it in the Javadoc...

I've also read than knnmatch() can probably help me but I don't understand how. I already have my four points with "the best distance" when I follow the tutorial.

If I follow my instinct, the false-positive have to be detect after the findHomography() function. Nope ?

Is there somebody who can help me with my outliers ? :)

2013-04-23 07:50:27 -0600 commented answer False positive in object detection

Thank you very much for all those idea! I'll try all of them and see which one is the best in my case !

2013-04-22 04:17:27 -0600 commented question False positive in object detection
2013-04-18 02:32:49 -0600 asked a question False positive in object detection

Hi !

I've follow the tutorial "object detection in a scene" and that's work pretty well. But I still have a question.

In my little app, i want to know which object (in a list) is in the scene. When the object is really in the scene, there is no problem (that's a really good point). But the algorithm is always finding a match, even if the object is not in the scene. Most of the time, when the result is wrong, the 4 points don't form a square, it's a line, a big point or something like an hourglass.

Is there a function who can detect / evaluate the probability of a false positive, or i have to do some math by myself ? :)

2013-04-18 02:12:05 -0600 commented answer The homography tutorial in java

Hi,

Sorry for my late, i havn't see your answer. You shoul try this way :

Mat hg = Calib3d.findHomography(obj, scene, 8, 10);

//8 for RANSAC //10 for the reprojection error

Hop it will help you !

2013-04-09 08:37:53 -0600 commented answer OpenCV Java for a multiplatform app

Yes, that's a problem. That's why i'm don't know how to deal with this dll.

If there was a ".so" file instead of the dll, i will do something like :

String system = System.getProperty("os.name"); if system == Windows extension = "dll"; else extension = "so"

But there is not =/ Or i havn't found how to create them...

2013-04-09 08:13:32 -0600 commented answer OpenCV Java for a multiplatform app

So... after a day of trying... i havn't succeed with that. But i've found an other way to do it : in eclipse, i've create a dependance between the two project. This way, when i build my project, the dll are found :)

But i still have a problem... how to deal with the dll ? Remember, i want to create a multiplatform app thank's to the java support, and i havn't found any .so files =/

2013-04-08 06:49:01 -0600 commented answer OpenCV Java for a multiplatform app

How can i add this dll ?

When i create my jar in eclipse, i've check the box "Package required library into generated jar"

2013-04-08 05:05:14 -0600 asked a question OpenCV Java for a multiplatform app

Hi,

I'm trying to create a multiplaform app with OpenCV. The Java Support was pretty much a good news for me :)

I've install OpenCV, create a first app on windows and i'm trying to make an executable jar. But i suppose i'll have a lot of problem thanks to the dll...

I've create in Eclipse a jar who include all the libraries needed. If a create a new project on windows, import my new jar, i can create object declared in my jar but when i run :

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java244 in java.library.path

And if i do the same thing on a RedHat, i've also an error :

Exception in thread "main" java.lang.NoClassDefFoundError: org/opencv/highgui/Highgui
    at core.Ident.ident(Ident.java:84)
    at Main.main(Main.java:13)

(Ident.java:84 is the first line using an OpenCV command)

Would anyone have a tips or a link to a good step-by-step of creating a multiplatform runnable Jar in eclipse with Open CV in it ?

Thanks in advance.

Edit : So... after a day of trying... i havn't succeed with that. But i've found an other way to do it : in eclipse, i've create a dependance between the two project. This way, when i build my project, the dll are found :)

But i still have a problem... how to deal with the dll ? Remember, i want to create a multiplatform app thank's to the java support, and i havn't found any .so files =/