Ask Your Question

swamynathan's profile - activity

2018-04-26 09:25:04 -0600 received badge  Popular Question (source)
2017-10-06 01:54:56 -0600 received badge  Popular Question (source)
2016-07-01 08:17:11 -0600 received badge  Famous Question (source)
2015-04-11 08:18:03 -0600 received badge  Notable Question (source)
2014-09-04 10:48:34 -0600 received badge  Popular Question (source)
2013-08-09 11:30:36 -0600 commented question Keypoint matcher matches all keypoints from train to query irrespective of the scene?

Using fllannbased matcher gives error

OpenCV Error: Assertion failed (type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)) in void cv::batchDistance(cv::InputArray, cv::InputArray, cv::OutputArray, int, cv::OutputArray, int, int, cv::InputArray, int, bool), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/stat.cpp, line 1797
2013-08-08 19:48:44 -0600 asked a question Recognise known object - findHomography and perspective Transform

I'm trying to detect known object in real time using feature2d there is no proper trapezoid formed at output if i draw border using line or rectangle - All I get is random lines(mostly dots) changing irrespective of the presence of object inside camera frame.

The complete code is here

Now I changed detector, descriptor and matcher from above to

    FeatureDetector detector = FeatureDetector.create(FeatureDetector.FAST);
    DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);

I now get good-matches depending on condition

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

THE logcat now is

Keypoints Size: 1x676 
KeypointsRef Size : 1x139
descriptor Size: 32x629
descriptorRef Size : 32x32
Matches Size: 1x32
matchesList Size: 32
LIST D MATCH -- Max dist : 447.1934814453125 -- Min dist : 100.0
good matches size: 5
gm from good_matches Size: 1x5
obj Size: 1x5
scene Size: 1x5
Calib3d.findHomography  hg Size: 3x3

Frame - 1

hg : [-1.946750073879795, -2.153719667711051, 161.7932939049003;
      -2.245372221173412, -2.194859343368184, 175.7583814286593;
      -0.01283591450941816, -0.01266823891952267, 0.9999999999999999]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [161.79329, 175.75838; 141.15591, 174.06831; 157.10199, 173.61986; 213.06747, 160.14717]

Frame-2

hg : [-1.934167716139827, -4.236308808871488, 249.7027233816234;
      -0.8409584670694304, -1.643347407920087, 101.4526716763755;
      -0.007981402185299564, -0.01677063017280203, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [249.70273, 101.45267; 209.01646, 123.05411; 247.24049, 101.07324; 257.63394, 91.981918]

Frame-3

hg : [18.44625165513222, -30.49302758685548, 245.9935488915967;
       8.983047514459511, -15.26849377435921, 134.9835860140666;
       0.07275391289238894, -0.1212195797795232, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [245.99355, 134.98358; 252.92078, 124.42062; 274.09152, 100.6524; 252.08675, 125.08897]

Frame-4

hg : [2523.743444745383, -3436.790363876738, -6320.163263697045;
      1152.68745032164, -1181.519781694952, -18248.99783312392;
      10.26100642365376, -14.53251070681075, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [-6320.1631, -18248.998; 241.77501, 100.64852; 277.01508, 229.64558; 241.293, 94.730072]

the "obj_corners is equal to the reference image dimensions(153*94)"

but the "scene_corners is either negative or random and mostly all points are almost at the same location".

the findHomography hg value is sometimes negative

and the perspectiveTransform scene_corners is either negative or random and mostly all points are almost at the same location.

Is the problem with output of findHomography or perspectiveTransform?

2013-08-08 18:32:19 -0600 commented answer The homography tutorial in java

@Sylvian:

There's a slight mistake

Mat hg = Calib3d.findHomography(obj, scene, 8, 10); //8 for RANSAC //10 for the reprojection error

but if you look here there's no 10 as constant field value for the Calib3d in openCV

and it doesn't work. please clarify

2013-08-07 19:23:27 -0600 commented question Android application to recognize and track object from camera has more false positives?

I added condition

if(good_matches.rows() &gt;= 4)

before forming objList and sceneList with query and train Idx

2013-08-07 11:03:00 -0600 commented question Keypoint matcher matches all keypoints from train to query irrespective of the scene?

This project is real time detection from camera frame http://answers.opencv.org/question/17723/android-application-to-recognize-known-object-and/

What if the reference image is not present in the scene there should be no matches right(when I point the camera towards white background there's matches and border lines are drawn in the output but are skewed and not pointing to anything).

All I need is to detect the presence of the reference object in the camera frame what feature extraction, detection and matching I should use.

Are there any clear openCV documentation for object recognition?

2013-08-06 22:30:56 -0600 asked a question Keypoint matcher matches all keypoints from train to query irrespective of the scene?

I am using feature detection to recognize known object inn a real time camera frame with android but matcher shows every keypoint from the object image is matched to the keypoints in the scene/camera frame.

the logcat outputs the keypoint and matched info

08-07 01:40:13.899: I/OCVSample::Activity(26175): mGray H/W  : 320x240
08-07 01:40:13.899: I/OCVSample::Activity(26175): mRef H/W  : 153x94
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypoints H/W  : 1x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypointsRef H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptor Size: 32x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptorRef Size : 32x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): Matches Size: 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): matchesList Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): LIST D MATCH -- Max dist : 97.0 -- Min dist : 67.0
08-07 01:40:13.899: I/OCVSample::Activity(26175): good_matches Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches   : Mat [ 33*1*CV_32FC4, isCont=true, isSubmat=false, nativeObj=0x6761d8, dataAddr=0x8bef80 ]

the code is

FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);

detector.detect(mGray, keypoints);
detector.detect(mRef, keypointsRef);

extractor.compute(mGray, keypoints, descriptor);
extractor.compute(mRef, keypointsRef, descriptorRef);

matcher.match(descriptorRef, descriptor, matchs);

List<DMatch> matchesList = matchs.toList();
    Double max_dist = 0.0;
    Double min_dist = 100.0;

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


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

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

    gm.fromList(good_matches);          
  Log.i(TAG, "gm from good_matches Size: " + gm.size());

what is the problem with matcher.

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ UPDATE /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

OK now I use

    FeatureDetector detector = FeatureDetector.create(FeatureDetector.FAST);
    DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);

I now get good-matches less than no of reference keypoints depending on condition below

  if (matchesList.get(i).distance <= (3 * min_dist)) {
 good_matches.addLast(matchesList.get(i));
}

The logcat now shows(compare-previous)

Keypoints Size: 1x676 
KeypointsRef Size : 1x139
descriptor Size: 32x629
descriptorRef Size : 32x32
Matches Size: 1x32
matchesList Size: 32
LIST D MATCH -- Max dist : 447.1934814453125 -- Min dist : 100.0
good matches size: 5
gm from good_matches Size: 1x5
obj Size: 1x5
scene Size: 1x5
Calib3d.findHomography  hg Size: 3x3

A few output samples

Frame - 1

hg : [-1.946750073879795, -2.153719667711051, 161.7932939049003;
      -2.245372221173412, -2.194859343368184, 175.7583814286593;
      -0.01283591450941816, -0.01266823891952267, 0.9999999999999999]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [161.79329, 175.75838; 141.15591, 174.06831; 157.10199, 173.61986; 213.06747, 160.14717]

Frame-2

hg : [-1 ...
(more)
2013-08-06 19:53:03 -0600 commented question OpenCV Assertion Failed for Perspective Transform.

Thanks 2 you

2013-08-06 19:52:34 -0600 commented answer OpenCV Assertion Failed for Perspective Transform.

Thanks it solved this problem.

2013-08-06 19:52:01 -0600 received badge  Scholar (source)
2013-08-05 19:18:35 -0600 asked a question OpenCV Assertion Failed for Perspective Transform.

For this part of code from this application code

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

    Mat obj_corners = new Mat(4,1,CvType.CV_32FC1);
    Mat scene_corners = new Mat(4,1,CvType.CV_32FC1);

    Core.perspectiveTransform(obj_corners, scene_corners, hg);

This is the error, also tried changing the type to CV_8UC1, CV_32F and CV_32FC1

08-06 05:37:35.219: E/cv::error()(17414): OpenCV Error: Assertion failed (scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F)) in void cv::perspectiveTransform(cv::InputArray, cv::OutputArray, cv::InputArray), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matmul.cpp, line 1926
08-06 05:37:35.229: W/dalvikvm(17414): threadid=11: thread exiting with uncaught exception (group=0x40ad59f0)
08-06 05:37:35.229: E/AndroidRuntime(17414): FATAL EXCEPTION: Thread-5874
08-06 05:37:35.229: E/AndroidRuntime(17414): CvException [org.opencv.core.CvException: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matmul.cpp:1926: error: (-215) scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F) in function void cv::perspectiveTransform(cv::InputArray, cv::OutputArray, cv::InputArray)
08-06 05:37:35.229: E/AndroidRuntime(17414): ] 
08-06 05:37:35.229: E/AndroidRuntime(17414):    at org.opencv.core.Core.perspectiveTransform_0(Native Method)
08-06 05:37:35.229: E/AndroidRuntime(17414):    at org.opencv.core.Core.perspectiveTransform(Core.java:5869)
08-06 05:37:35.229: E/AndroidRuntime(17414):    at com.example.objectrecognition.MainActivity.onCameraFrame(MainActivity.java:279)
08-06 05:37:35.229: E/AndroidRuntime(17414):    at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:376)
08-06 05:37:35.229: E/AndroidRuntime(17414):    at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:294)
08-06 05:37:35.229: E/AndroidRuntime(17414):    at java.lang.Thread.run(Thread.java:856)

The MainActivity.java:279 referes to the line

Core.perspectiveTransform(obj_corners, scene_corners, hg);

When I use log for the two I get

obj_corners : Mat [ 4*1*CV_32FC1, isCont=true, isSubmat=false, nativeObj=0x677d18, dataAddr=0x7de5a0 ]
scene_corners : Mat [ 4*1*CV_32FC1, isCont=true, isSubmat=false, nativeObj=0x677d58, dataAddr=0x5d9c80 ]

What am I missing here?

2013-08-05 18:37:01 -0600 asked a question Data usage warning for android application.

The project of object detection shown here shows data usage warning for Application Name(Object Reco) in my sony ST23i and the installed application memory is 1.39Mb but at runtime it rises upto 15Mb or more what might be the problem?

The application opens only once and the next time I'll have to uninstall and install it again is matrix created giving any problems?

Logcat errors for resuming/launching through android device

OpenCV Error: Assertion failed (type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)) in void cv::batchDistance(cv::InputArray, cv::InputArray, cv::OutputArray, int, cv::OutputArray, int, int, cv::InputArray, int, bool), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/stat.cpp, line 1797

the complete source here

2013-08-05 14:35:18 -0600 edited question Android application to recognize and track object from camera has more false positives?

I'm really new to openCV I followed this but detection too slow

mRgba matrix from camera input
mRef matrix from object image

FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
detector.detect(mGray, keypoints);
detector.detect(mRef, keypointsRef);     
extractor.compute(mGray, keypoints, extract);
extractor.compute(mRef, keypointsRef, extractRef);
matcher.match(extractRef, extract, matchs);
List<KeyPoint> keypoints_RefList = keypointsRef.toList();
List<KeyPoint> keypoints_List = keypoints.toList();
if (matchesList.get(i).distance <= (3 * min_dist)) {
 good_matches.addLast(matchesList.get(i));  
}
for (int i = 0; i < good_matches.size(); i++) {
  objList.addLast(keypoints_RefList.get(good_matches.get(i).queryIdx).pt);
  sceneList.addLast(keypoints_List.get(good_matches.get(i).trainIdx).pt);
}  
obj.fromList(objList);
scene.fromList(sceneList);
Mat hg = Calib3d.findHomography(obj, scene, 8, 2, new Mat());
Mat obj_corners = new Mat(4,1,CvType.CV_32FC2); 
Mat scene_corners = new Mat(4,1,CvType.CV_32FC2);
obj_corners.put(0, 0, new double[] {0, 0});
obj_corners.put(1, 0, new double[] {mRef.cols(), 0});
obj_corners.put(2, 0, new double[] {mRef.cols(), mRef.rows()});
obj_corners.put(3, 0, new double[] {0, mRef.rows()});
Core.perspectiveTransform(obj_corners, scene_corners, hg);
Core.line(mRgba, new Point(scene_corners.get(0,0)), new Point(scene_corners.get(1,0)), new Scalar(0, 255, 0),3);
Core.line(mRgba, new Point(scene_corners.get(1,0)), new Point(scene_corners.get(2,0)), new Scalar(0, 255, 0),3);
Core.line(mRgba, new Point(scene_corners.get(2,0)), new Point(scene_corners.get(3,0)), new Scalar(0, 255, 0),3);
Core.line(mRgba, new Point(scene_corners.get(3,0)), new Point(scene_corners.get(0,0)), new Scalar(0, 255, 0),3);

This is way too wrong it detects almost anything as output and draws random points as output.

Is there a way to refine the detection?

Can histogram, dialate or smooth options be applied to the images?

2013-07-31 11:55:36 -0600 commented answer Android application to recognize and track object from camera has more false positives?

I checked them all to be not empty and their sizes were not zero. I added

if(goood_matches.size() &gt;= 4){

before the for loop where addLast objList and sceneList it still finds matches even when object is not present in scene