I configured Opencv 2.4.13 in my visual studio 2012. I used the pre-compiled version of opencv, so I didn't compile nothing. By the way, I setted everything ( I followed tutorial in internet) and my simple programs (such as "show an image") work well. So my OpenCv are installed and they are working.
Now, I try to execute this simple program: I read a video and then i take first frame and use SIFT detector and descriptor on it.
My visual studio stops to work when I arrive in SIFT detector line. This is my code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp> // SIFT
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <string>
#include <iomanip>
#include <stdlib.h>
#include "Histogram.hpp"
#include "Util.hpp"
using namespace std;
using namespace cv;
int main()
{
VideoCapture video;
Mat frame;
int i = 0;
SiftFeatureDetector siftDetector;
SiftDescriptorExtractor siftDescriptor;
vector<KeyPoint> siftKeypoints;
FileStorage fs("keypointDescriptors.yml", FileStorage::WRITE);
string frameName = "";
string frameStringNumber;
ostringstream convert;
Mat_<float> descriptors;
// Apro il video
try {
video.open("person15_walking_d1_uncomp.avi");
}
catch (Exception ex) {
cout << ex.msg;
return -1;
}
video.read(frame);
siftDetector.detect(frame, siftKeypoints);
siftDescriptor.compute(frame, siftKeypoints, descriptors);
waitKey(0);
return 0;
}
The error is:
Unhandled exception in 0x0085370A (opencv_imgproc2413d.dll) in ConsoleApplication4.exe: 0xC000001D: Illegal Instruction.
Related
I am using the tensorflow c++ API in my code. And I found when I load image from files the image is NULL. Then I write a test code to find the reason.
Here is my test code:
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
//#include "tensorflow/core/public/session.h"
//#include "tensorflow/core/protobuf/meta_graph.pb.h"
int main()
{
Mat imgtry = imread("lena.jpg");
printf("%dx%d", imgtry.cols, imgtry.rows );
return 0;
}
When I comment tensorflow's header, the output value is 255x255, but once I uncomment the header, the output value is 0x0. Why ???
The problem seems change slightly after I revised the sequence of link library. At first, I link the tensorflow_cc and tensorflow_frameworok and then the opencv's libriries. Now, I put the tensorflow's libraries after the opencv and the let corresponding include directory as the same sequence. Then I can read image normally even uncomment the code in the above code area. But new porblem occured.
#include "opencv2/opencv.hpp"
#include "opencv2/imgcodecs.hpp"
//it's ok.
#include "tensorflow/core/public/session.h"
#include "tensorflow/core/protobuf/meta_graph.pb.h"
using namespace std;
int main()
{
cv::Mat img;
img = cv::imread("lena.jpg");
if(img.empty() == true) {
cout << "Error!" << endl;
exit(1);
}
cout << "ok!" << endl;
//uncomment this, the img is always emtpy!!!
// tensorflow::SessionOptions sessOptions;
// sessOptions.config.mutable_gpu_options()->set_allow_growth(true);
// auto session = tensorflow::NewSession(sessOptions);
// if(session == nullptr) {
// cout << "Could not create Tensorflow session." << endl;
// exit(1);
// }
return 0;
}
It's a known bug
Feel free to update this Community Wiki answer with Workaround / Solution / Bug status / Etc...
Compiled opencv 3.2.0 to mingw - codeblocks in windows 10 creators
i can write programs in opencv, they run, e.g. Lena.cpp.
but when i need the camera, the program run, making the window but it doesn't show the camera(0) of the laptop.
Here's the code:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main() {
VideoCapture stream1(0); //0 is the id of video device.0 if you have only one camera.
if (!stream1.isOpened()) { //check if video device has been initialised
cout << "cannot open camera";
}
//unconditional loop
while (true) {
Mat cameraFrame;
stream1.read(cameraFrame);
imshow("cam", cameraFrame);
if (waitKey(30) >= 0)
break;
}
return 0;
}
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
int main(){
VideoCapture vcap("0");
if(!vcap.isOpened()){
cout << "Error opening video stream or file" << endl;
return -1;
}
int frame_width= vcap.get(CV_CAP_PROP_FRAME_WIDTH);
int frame_height= vcap.get(CV_CAP_PROP_FRAME_HEIGHT);
VideoWriter video("~/out.avi", CV_FOURCC('J','P','E','G'), 10, Size(frame_width,frame_height),true);
for(;;){
Mat frame;
vcap >> frame;
video << frame;
imshow( "Frame", frame );
char c = (char)waitKey(33);
if( c == 'q' ) break;
}
return 0;
}
I have tried the above code, the program can correctly show the camera image through imshow(), but after terminate the program, no video output file has written to the disk. I use MacOS Xcode and OpenCV 2.4.13 as development platform. The same work and output the video file completely on Windows Visual Studio. Please help.
#include <iostream>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/calib3d/calib3d.hpp>
using namespace std;
using namespace cv;
int main()
{
char filename[] = "IMG_0851";
Mat image; //create an image matrix
I want to analysis the image in grayscale
image = cvLoadImage(filename,CV_LOAD_IMAGE_GRAYSCALE); //load image in grayscale directly
if (image.empty())
{
cout << "Image could not be found" << endl;
return -1;
}
imshow("Image in RGB", image);
cvWaitKey(0); //wait for a keystroke in the window
return 0;
}
Build succeeded, however, the image cannot be found & program ended exit code: 255.
I recently reinstalled Ubuntu - 12.04. I am using webcam to take video for a program in OpenCV. It doesn't work for my webcam, but the same piece of code works for my friend.
My webcam works with Cheese.
The piece of code I am using is:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define heightBirdEyeView 1000
#define widthBirdEyeView 1000 //earlier was 300 300
#define _USE_MATH_DEFINES
//public class VideoCapture;
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened())
{ // check if we succeeded
cout<<"cam not open"<<endl;
return -1;}
cout<<"yay"<<endl;
Mat frame;
while(1)
{
cap >> frame;
imshow("frame", frame);
if(waitKey(30) >= 27)
break;
}
return 0;}
What could be wrong?
v4l2 or v4l can be missing, please check your make output.. It should highgui problem.