I have a simple program that uses Brisk detection and flann matching. I'm looking to improve the efficiency by applying the detection to a specific region of interest in each frame. I've tried the following:
cv::Mat ROI_scene, scene;
//region of interest
cv::Rect myROI(10, 10, 100, 100);
cv::Ptr<BRISK> detector = BRISK::create();
cv::Ptr<BRISK> descriptorExtractor = BRISK::create();
while ( capture.read(scene) )
{
ROI_scene = scene(myROI);
detector->detect(ROI_scene, keypoints_scene);
descriptorExtractor->compute(ROI_scene, keypoints_scene, descriptors_scene);
matcher.match(descriptors_object, descriptors_scene, matches);
}
The above returns this error:
OpenCV Error: Bad argument (Only continuous arrays are supported) in
buildIndex_, file opencv/3.0.0/modules/flann/src/miniflann.cpp, line
317 libc++abi.dylib: terminating with uncaught exception of type
cv::Exception: opencv/3.0.0/modules/flann/src/miniflann.cpp:317:
error: (-5) Only continuous arrays are supported in function
buildIndex_
Abort trap: 6
I've also tried using copyTO and then I get a Arrays must be 2d or 3d error.
Any insight would be really helpful
Here is a gist of the working code:
https://gist.github.com/DevN00b1/63eba5813926e4d0ea32
Related
I want to detect circular round black blobs in opencv2
detector = cv2.SimpleBlobDetector(params)
keypoints = detector.detect(im)
I am getting error:
keypoints = detector.detect(im)
TypeError: Incorrect type of self (must be 'Feature2D' or its
derivative)
You can use this instead:
detector = cv2.SimpleBlobDetector_create(params)
This changed with OpenCV version 2 onwards.
I am a beginner in OpenCV feature detection and matching. I am trying to write one simple method to detect and display the detected feature with an image.Here is the method that I have written:
void FeatureDetection::detectSimpleFeature(Mat image){
Mat gray_image, output_image;
cvtColor(image,gray_image,CV_BGR2GRAY);
// Detect Keypoints using Simple Detector
Ptr<Feature2D> detectors;
vector<KeyPoint> keypoint_1;
detectors->detect(image, keypoint_1);
drawKeypoints(gray_image, keypoint_1, output_image, Scalar::all(-1), DrawMatchesFlags:: DEFAULT);
namedWindow("Keypoints Detection");
imshow("Keypoints Detection", output_image);
waitKey(0);
}
There is no compile time error in this function, but while running, the program is crashing.Can anyone please help?
I am also searching special types of detector like SURF, SIFT etc but could not find in my downloaded and built library. Please suggest !!!
I am trying to do classification of images with combining SIFT features, Bag of Visual Words and SVM.
Now I am on training part. I need to get BoW histograms for each training image to be able to train SVM. For this I am using BOWImgDescriptorExtractor from OpenCV. I am using OpenCV version 3.1.0.
The problem is that it computes histogram for some images, but for some of images it gives me this error:
OpenCV Error: Assertion failed (queryIdx == (int)i) in compute,
file /Users/opencv-3.1.0/modules/features2d/src/bagofwords.cpp, line 200
libc++abi.dylib: terminating with uncaught exception of type
cv::Exception: /Users/opencv-3.1.0/modules/feature/src/bagofwords.cpp:200: error: (-215) queryIdx == (int)i in function compute
Training images are all of the same size, all have same number of channels.
For creating dictionary I use another image set than for training SVM.
Here's part of code:
Ptr<FeatureDetector> detector(cv::xfeatures2d::SIFT::create());
Ptr<DescriptorMatcher> matcher(new BFMatcher(NORM_L2, true));
BOWImgDescriptorExtractor bow_descr(det, matcher);
bow_descr.setVocabulary(dict);
Mat features_svm;
for (int i = 0; i < num_svm_data; ++i) {
Mat hist;
std::vector<KeyPoint> keypoints;
detector->detect(data_svm[i], keypoints);
bow_descr.compute(data_svm[i], keypoints, hist);
features_svm.push_back(hist);
}
data_svm is a vector<Mat> type. It is my training set images which I will use in SVM.
What the problem can be?
I ran into the same issue. I was able to fix it by changing the cross check option of the Brute Force matcher to False. I think its because the cross check option keeps only a select few matches and removes the rest and messes up the indexes in the process
I am new to OpenCV in general and have been trying out a number of examples over the past few days. I've successfully gotten Harris corner detections to work on some test images. My next test was to see if I could match two images based on the harris detections using SIFT.
Here is how I found harris corners:
GoodFeaturesToTrackDetector harris_detector(1000, 0.01, 10, 3, true);
vector<KeyPoint> keypoints1, keypoints2;
harris_detector.detect(img1, keypoints1);
harris_detector.detect(img2, keypoints2);
This works well. With my next goal of matching the features between img1 and img2, I try to use SIFT. However, when I try to declare an extractor for SIFT:
SiftDescriptorExtractor extractor;
I get the following error:
error: ‘SiftDescriptorExtractor’ was not declared in this scope
SiftDescriptorExtractor extractor;
What am I doing wrong?
Thanks in advance.
Make sure you have #include <features2d.hpp>.
In some versions of OpenCV, Sift are in <opencv2/nonfree/features2d.hpp>.
when using BOWImgDescriptorExtractor with DescriptorExtractor as SIFT and DescriptorMatcher as ButeForce i am getting error as
OpenCV Error: Assertion failed (queryDescriptors.type() == trainDescCollection[0].type()) in knnMatchImpl,
what could me my error.
when i am trying to compute
eg.
bowide->compute(img, keypoints, response_hist);
I had the same error using the Surf feature detector and extractor with BFMatcher.
The error occurs because the query descriptor mat and train descriptor mat doesn't have the same type - as stated in your error message.
This happened to me only when no keypoints for the train or query image could be calculated by the feature detector.
Check that the size of your keypoints vector is not zero before doing the matching.
I also had the same error. There is another possible reason: the dtype of the dictionary should be float32. It turns out that I did some operations with the dictionary with numpy before calling the setVocabulary function, which changed the dtype of the dictionary implicitly.