Ask Your Question

jamescharters's profile - activity

2016-04-29 05:18:44 -0600 received badge  Famous Question (source)
2015-08-03 13:18:05 -0600 received badge  Notable Question (source)
2015-03-18 04:45:51 -0600 received badge  Popular Question (source)
2013-09-02 18:39:55 -0600 received badge  Editor (source)
2013-09-02 18:38:18 -0600 answered a question How to use bag of words example with BRIEF descriptors?

Just reposting from the comments above with nice code formatting.

In short, there appears to be an issue when using the BOWImgDescriptorExtractor on the above ORB BoW approach. This might trip up other people, and seems closely related to the above question.

Here is some sample code:

int dictionarySize = 1024;
TermCriteria tc(CV_TERMCRIT_ITER, 10, 0.00001);
int retries = 1;
int flags = KMEANS_PP_CENTERS;

// How the objects are set up
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce");
Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create("ORB");
Ptr<FeatureDetector> detector = FeatureDetector::create("Dense");
BOWKMeansTrainer bowTrainer(dictionarySize, tc, retries, flags);
BOWImgDescriptorExtractor bowDE(extractor, matcher)

// ...
// ... code here is equivalent to answer above for computing BoW but has been excluded for brevity ... 
// ...

// Read in the image that we want to match against the descriptor
Mat img = imread(entryPath.string(), 1);
cvtColor(img, img, CV_BGR2GRAY);

// Get the keypoints
vector<KeyPoint> keypoints;
detector->detect(img, keypoints);

// Try to get the descriptor
Mat bowDescriptor = Mat(0, 32, CV_32F);
bowDE.compute(img, keypoints, bowDescriptor); // <-- errors here

And the error is:

"OpenCV Error: Assertion failed (queryDescriptors.type() == trainDescCollection[0].type()) in knnMatchImpl, file /Users/jamescharters/Downloads/opencv-2.4.6.1/modules/features2d/src/matchers.cpp, line 351"

I am doing this in C++ using OpenCV 2.4.6.1 on Mac OS 10.8.4.

2013-09-02 03:43:32 -0600 commented answer How to use bag of words example with BRIEF descriptors?

Code for above:

// How the objects are set up

Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce");

Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create("ORB");

Ptr<FeatureDetector> detector = FeatureDetector::create("Dense");

BOWKMeansTrainer bowTrainer(dictionarySize, tc, retries, flags);

BOWImgDescriptorExtractor bowDE(extractor, matcher)

...

// Read in the image

Mat img = imread(entryPath.string(), 1);

cvtColor(img, img, CV_BGR2GRAY);

// Get the keypoints

vector<KeyPoint> keypoints;

detector->detect(img, keypoints);

// Try to get the descriptor

Mat bowDescriptor = Mat(0, 32, CV_32F);

bowDE.compute(img, keypoints, bowDescriptor); // errors here

2013-09-02 03:12:44 -0600 commented answer How to use bag of words example with BRIEF descriptors?

Thanks for the helpful post, Mathieu.

However, there are issues if you are using BOWImgDescriptorExtractor, particularly when calling compute() on that class.

If you do as above to build the BoW clusters then create a BOWImgDescriptorExtractor using a BruteForce matcher and ORB extractor, there is an error.

  1. I read in a greyscale image
  2. I compute the keypoints using the DenseFeatureDetector
  3. I call compute() on the BOWImgDescriptorExtractor object which throws the following error:

"OpenCV Error: Assertion failed (queryDescriptors.type() == trainDescCollection[0].type()) in knnMatchImpl, file /Users/jamescharters/Downloads/opencv-2.4.6.1/modules/features2d/src/matchers.cpp, line 351"

Am I missing something easy here? Thanks.

2013-09-02 03:04:37 -0600 received badge  Supporter (source)
2013-08-30 07:07:10 -0600 commented answer Drawing lines, rectangles on Mat using Java wrapper stuck at 0,0?

Yep I definitely will. Thank you for the timely help and advice with this issue!

2013-08-30 05:11:51 -0600 commented answer Drawing lines, rectangles on Mat using Java wrapper stuck at 0,0?

Hi Steven, sorry for the late reply. Your approach in C++ works as expected, but the JVM segfaults for some reason when I run the Java equivalent. I will do a bit more investigation tomorrow when I have some time...

2013-08-20 18:11:49 -0600 commented answer Drawing lines, rectangles on Mat using Java wrapper stuck at 0,0?

Hi Steven, thanks so much for the C++ example. I will try this approach in both C++ and Java myself and report back on what the results are shortly

2013-08-20 05:07:05 -0600 commented question Drawing lines, rectangles on Mat using Java wrapper stuck at 0,0?

Hi Steven, thank you for the reply. I've tried reading the image in as greyscale and drawing. No luck so far!

2013-08-17 04:10:44 -0600 received badge  Student (source)
2013-08-16 19:31:40 -0600 asked a question Drawing lines, rectangles on Mat using Java wrapper stuck at 0,0?

Hi All,

I am using OpenCV 2.4.6.1 on OSX 10.8.4 using the Java API with IntelliJ. I am developing a very simple application that works on a 640x480 24bpp Mat object which is an image read in from disk.

I have code to draw rectangles and lines, but despite changing the point coordinates for start and end only a single pixel is drawn at 0,0 of the Mat. The lines and rectangles seem to ignore any combination of coordinates I give and always result in this strange result. Here is some code:

Mat color_origImg = Highgui.imread("/Users/jamescharters/Downloads/sample_0_bw_hog-rect.jpg");
Core.line(color_origImg, new Point(50,50), new Point(10, 100), new Scalar(255,0,0), 1);
Highgui.imwrite("/Users/jamescharters/Downloads/sample_0_bw_hog-rect.jpg", color_origImg);

The image is definitely being read in correctly but I can't for the life of me figure out why plotting lines, rectangles or other sorts of shapes on a Mat object doesn't work as expected. I've tried black and white images, using CvtColor too ... all to no avail.

Can anyone offer some advice?