OpenCV 3.1. SURF and SIFT C++ - c++

Does anyone have solution for this problem:
Ptr<SURF> detector = SURF::create(minHessian);
std::vector<KeyPoint> keypoints_object;
detector->detect( inImage, keypoints_object );
It gives me Unhandeled exeption error while going throu detect function. I have linked the xfeatures2d module and included it into file, also I included nonfree.hpp, which is part of xfeatures2d. In earlier versions, this problem was solved using initModule_nonfree(), I think, but here, this function do not exist. Thanks in advance.

Related

Cannot convert OpenCV Mat to dlib arrray2D

I am using the following code to convert an cv::Mat into dlib array2D (which is required to track objects through dlib correlation tracker)
int main()
{
cv::Mat img = cv::imread("wine_plant.jpg");
dlib::cv_image<dlib::bgr_pixel> dlib_img(img);
return 0;
}
But while debugging I get the following error message.
Error C2440 'initializing': cannot convert from 'const cv::Mat' to 'IplImage' yolo_cywine c:\users\antho\documents\c++\dlib-19.7\source\dlib\opencv\cv_image.h 37
Based on other issues already opened on the same matter, I also tried this
cv::Mat img = cv::imread("wine_plant.jpg");
dlib::cv_image<unsigned char> dlib_img(img);
But same result.
Am I missing something or is there something I am doing wrong? Could you please help me out?
Thanks in advance.
Your dlib version 19.7 seems too old. I also faced similar error on dlib 19.19 downloading from its website. It was fixed on github, but http://dlib.net/ did not contain the fixes when I used it. For me compiling from source solved it. Newer dlib version should fix this error.
These issues discuss this problem,
https://github.com/davisking/dlib/issues/1955
https://github.com/davisking/dlib/issues/1949
https://github.com/davisking/dlib/issues/2071
Changes to cv_image.h,
https://github.com/davisking/dlib/commits/master/dlib/opencv/cv_image.h
https://github.com/davisking/dlib/commit/54a9a5bbf3267386dd39a82fb792bab1bb60796c#diff-7c8f1a39b770981bf2d3a132da6f083b130b7c52cd994dbccb1d2115f0d729fd
https://github.com/davisking/dlib/commit/a4bf6e1e6afef5c55414164dc4414908d91a8be5#diff-7c8f1a39b770981bf2d3a132da6f083b130b7c52cd994dbccb1d2115f0d729fd

OpenCV 3: List of available FeatureDetector::create() and DescriptorExtractor::create() options?

edit: I was looking at the wrong OpenCV2 code example, there is no FeatureDetector::create in OpenCV3 - this was confusing me.
Hey new to OpenCV and learning by example by pulling apart other peoples C++ code.
I would like to try all available options for:
detector = FeatureDetector::create(str_detector);
descriptor = DescriptorExtractor::create(str_descriptor);
currently str_detector is FAST and str_descriptor is BRISK
I am having trouble finding what available Detectors and Descriptors are available to me.
Is there a way to output a list of all currently available options?
(I have just built the latest opencv + opencv-contrib from github on a fresh linux install)
I have found a list of 3rd party files here https://github.com/Itseez/opencv_contrib/tree/master/modules/xfeatures2d/src - I think these are 3rd Descriptors and Detectors because those words are mentioned in some of the files. However it would be nice to have a full list of currently compiled/available options to play with.
Thanks!
Trying to find the answer myself, edits as I go:
Found typedef Feature2D FeatureDetector and typedef Feature2D DescriptorExtractor in modules/features2d/include/opencv2/features2d.hpp
Digging for Feature2D now...
I'm so confused, my C++ is failing me, there is no create in https://github.com/Itseez/opencv/blob/master/modules/features2d/src/feature2d.cpp
ok so just looking through the code ( https://github.com/Itseez/opencv/blob/master/modules/features2d/include/opencv2/features2d.hpp )
BRISK
ORB
MSER
FastFeatureDetector / FAST
AgastFeatureDetector / AGAST
GFTTDetector
SimpleBlobDetector
KAZE / AKAZE
and from the contrib code ( https://github.com/Itseez/opencv_contrib/blob/master/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp )
FREAK
StarDetector
BriefDescriptorExtractor
LUCID
LATCH
DAISY
MSDDetector
and from nonfree contrib code ( https://github.com/Itseez/opencv_contrib/blob/master/modules/xfeatures2d/include/opencv2/xfeatures2d/nonfree.hpp )
SIFT
SURF
Still unsure which of the above can/should be used for FeatureDetector or DescriptorExtractor
You have also the OpenCV documentation to have a list of OpenCV features:
OpenCV 3.1 documentation
OpenCV 3.1 contrib documentation
What I do to know if the feature is available only in keypoints detection or descriptor extraction or both is to read the corresponding paper linked in the documentation. It allows also to have a brief description of the features (for example if it is a binary descriptor, main advantages, etc.)
Other solution is to test each feature:
if the call to detect() is ok (no exception thrown) ==> feature detection
if the call to compute() is ok ==> feature extraction
if the call to detectAndCompute() is ok ==> both
or looking directly into the source code.
Maybe a more optimal solution exists...
Anyway, from my knowledge (feel free to correct me if I am wrong):
BRISK: detector + descriptor
ORB: detector + descriptor
MSER: detector
FAST: detector
AGAST: detector
GFFT: detector
SimpleBlobDetector: detector
KAZE: detector + descriptor
AKAZE: detector + descriptor
FREAK: descriptor
StarDetector: detector
BriefDescriptorExtractor: descriptor
LUCID: descriptor
LATCH: descriptor
DAISY: descriptor
MSDDetector: detector
SIFT: detector + descriptor
SURF: detector + descriptor
Also with OpenCV 3.1, the code is:
cv::Ptr<cv::Feature2D> kaze = cv::KAZE::create();
std::vector<cv::KeyPoint> kpts;
cv::Mat descriptors;
kaze->detect(matImg, kpts);
kaze->compute(matImg, kpts, descriptors);
kaze->detectAndCompute(matImg, cv::noArray(), kpts, descriptors);
cv::Ptr<cv::Feature2D> daisy = cv::xfeatures2d::DAISY::create(); //Contrib
To know which norm type to use:
std::cout << "AKAZE: " << akaze->descriptorType() << " ; CV_8U=" << CV_8U << std::endl;
std::cout << "AKAZE: " << akaze->defaultNorm() << " ; NORM_HAMMING=" << cv::NORM_HAMMING << std::endl;
Finally, why
No more features2d::create?

How it should code in OpenCV 2.4 or OpenCV 3.0

I want to change this lines of code it original coded in opecv2.3 version
Ptr<DescriptorExtractor > extractor(new SurfDescriptorExtractor());// extractor;
new OpponentColorDescriptorExtractor(
Ptr<DescriptorExtractor>(new SiftDescriptorExtractor())
)
);
convert to openCV2.4 or OpenCV3.0.
Is anyone understand how i should code this ? Appreciated if you can share your guide. Thanks

OpenCV imwrite params read access violation

A very simple question...why am I getting a read access violation error with this code?
cv::Mat laserSpeckle = Mat::zeros(100,100,CV_8UC1);
imwrite( "C://testimage.jpg", laserSpeckle );
When i attach a debugger and look into it further, it throws the exception at this snippet in grfmt.cpp.
if( params[i] == CV_IMWRITE_JPEG_QUALITY )
{
quality = params[i+1];
quality = MIN(MAX(quality, 0), 100);
}
It occurs with .png and .tiff too. Im an OpenCV newbie, my apologies if this is something really simple. I am using Qt for what its worth.
Do you build OpenCV yourself? If yes, make sure that the option WITH_JPEG is enabled when you configure your build files:
cmake ... -DWITH_JPEG=ON ...
If you want to save image with alpha channel you should use png format. It is described here
It should work with bmp format:
cv::Mat laserSpeckle = cv::Mat::zeros(100,100,CV_8UC1);
cv::imwrite( "C://testimage.bmp", laserSpeckle );
Your code also works on my computer. However, it seems that on some systems it works only for bmp images. I saw similar issues reported here and here.
The problem is with the debugger version (x64) if you build the code using the release version (x64) it works fine for me.
In my case c++ Code Generation settings were wrong
Should have been Multithreaded DEBUG dll MD

OpenCV Cannot find MatND_

I was trying to update OpenCV (to 2.4.9) when I ran into a problem. I cannot find the file that defines "MatND_". In the old version of OpenCV it was in cxcore.cpp. I searched through google, the CV documentation and the new OpenCV library and found a lot of information regarding MatND but nothing relevant about MatND_. Does anyone know where I can find it? Thank you for your time.
Which version of OpenCV was "the old version". Even in 2.2 cxcore.hpp had comments about being deprecated and did not have MatND_. ?
If MatND_ is to MatND as Mat_ is to Mat, you may be able to just use aMat_`
MatND is declared in opencv2/core/core.hpp:
typedef Mat MatND;