I am using opencv 3.3.0
my code is
#include <stdio.h>
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/xfeatures2d.hpp"
#include <fstream>
#include <string>
#include <vector>
using namespace cv;
using namespace std;
using namespace cv::xfeatures2d;
int main(int argc, char** argv)
{
Mat img1;
img1 = imread("img/img1.jpg", IMREAD_GRAYSCALE);
if (img1.empty())
{
cout << "Could not open or find the image" << endl;
return -1;
}
Ptr<SurfFeatureDetector> detector = SurfFeatureDetector::create(400);
vector<KeyPoint> keypoints;
detector->detect(img1, keypoints);
imshow("img1", img1);
waitKey(0);
return 0;
}
I am new to C++ and opencv. The code work well without surf part.
error
OpenCV Error: Assertion failed (TlsSetValue(tlsKey, pData) == TRUE) in cv::TlsAbstraction::SetData, file C:\Users\Darshana\Documents\opencv\opencv-3.3.0\modules\core\src\system.cpp, line 1270
I have tried with Ptr<SURF> detector = SURF::create(400); as well.
UPDATE
I couldn't figure out a solution for this. Maybe a setup issue or library issue. So I just move to opencv 2.4.13 and now everything works fine. I had to change the above code to work with v2.4.13 though.
You haven't set parameter for SurfFeatureDetector. I think you should try this instead:
int minHessian = 400;
SurfFeatureDetector detector(minHessian);
vector<KeyPoint> keypoints;
detector.detect(img1, keypoints);
Related
I am kind of an intermediate in Computer Vison and fairly proficient in opencv python however coming to c++ i am facing problems in just selecting ROI from Video feed and displaying the cropped feed .My code looks like this.
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/tracking.hpp"
#include "iostream"
using namespace cv;
using namespace std;
int main() {
Mat frame1;
VideoCapture cap;
cap.open(0);
cap.read(frame1);
Rect2d roi = selectROI(frame1, true);
Mat Crop = frame1(roi);
while (1) {
cap.read(frame1);
Crop = frame1(roi);
if (Crop.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
imshow("roi", Crop);
int key=waitkey(0);
}
}
The code is compiling ,and the cropped window is seen however I am always in need to click enter,spacebar or esc to get the video feed.Weird?
So the correct version of the corrected code will look somewhat like this.Thanks for the help.
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/tracking.hpp"
#include "iostream"
using namespace cv;
using namespace std;
int main() {
Mat frame1;
VideoCapture cap;
cap.open(0);
cap.read(frame1);
Rect2d roi = selectROI(frame1, true);
Mat Crop = frame1(roi);
while (1) {
cap.read(frame1);
Crop = frame1(roi);
if (Crop.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
imshow("roi", Crop);
*int key=waitkey(1)*;
}
}
I'm trying to display an image 123.jpg on the screen, the display view did show up but the image didn't and the program exits with status 255
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat image;
image = cv::imread("123.jpg", CV_LOAD_IMAGE_UNCHANGED);
namedWindow("displayWindow", CV_WINDOW_AUTOSIZE);
imshow("displayWindow", image);
waitKey(0);
return 0;
}
Is there a problem in the code ?
error
error
#include<opencv\cv.h>
#include<opencv\highgui.h>
#include<opencv2\videoio.hpp>
using namespace cv;
int main(){
Mat image;
VideoCapture cap;
cap.open(0);
namedwindow("window",1);
while(1){
cap>>image;
imshow("window",image);
waitKey(33);
}
return 0;
}
when i try to run the program above i get the error that identifiers "namedWindow", "imshow" and "waitkey" are undefined.
i am coding in visual studio 2010.
You're including obsolete C code. To include the correct headers, use opencv2 and correct path.
Note that you can avoid all these includes, using the include all: #include <opencv2/opencv.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/video/video.hpp>
// or use only: #include <opencv2/opencv.hpp>
using namespace cv;
int main(){
Mat image;
VideoCapture cap;
cap.open(0);
namedWindow("window", 1);
while (1){
cap >> image;
imshow("window", image);
waitKey(33);
}
return 0;
}
if you use
#include<opencv\cv.h>
#include<opencv\highgui.h>
you have to use different, C functions, like cvNamedWindow("title"); and cvShowImage("title", img);
Use the following C++ includes:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2\opencv.hpp>
(you dont'h have to use all of them ...)
not sure how to proceed... still wet behind the ears, looking for advice.
//"strange" error using eclipse and opencv while following along in API
./src/captureCV.o: undefined reference to symbol '_ZN2cv12GaussianBlurERKNS_11_InputArrayERKNS_12_OutputArrayENS_5Size_IiEEddi'
and here's the cpp:
/*
* captureCV.cpp
*/
#include "opencv2/opencv.hpp"
#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
#include <string.h>
#include <stdio.h>
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
return 0;
}
not much to see just sample API material taken from openCV
build exits after executable is made.
I am new to OpenCV I was trying to read image in visual studio 2012 but was not able to load image using imshow but it works fine when I use cvLoadImage.
When I execute the following code it works fine but
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
using namespace std;
using namespace cv;
//char key;
int main()
{
IplImage *image = cvLoadImage("test1.jpg", CV_LOAD_IMAGE_GRAYSCALE);
cvNamedWindow("hah", WINDOW_AUTOSIZE);
cvShowImage("hah", image);
waitKey(5000);
return 1;
}`
but when I write the following code it throws an exception and image does not renders
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
using namespace std;
using namespace cv;
//char key;
int main()
{
Mat image = imread("test1.jpg");
namedWindow("My");
imshow("My", image);
waitKey(50000);
return 1;
}
I am not able to understand what is the problem.