#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include "opencv2/opencv.hpp"
#include <opencv2/highgui.hpp>
#include <iostream>
#include <Windows.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <direct.h>
#pragma comment(lib, "vfw32.lib")
#pragma comment( lib, "comctl32.lib" )
using namespace cv;
using namespace std;
void PrintFullPath(char * partialPath)
{
char full[_MAX_PATH];
if (_fullpath(full, partialPath, _MAX_PATH) != NULL)
printf("Full path is: %s\n", full);
else
printf("Invalid path\n");
}
int main(int argc, char** argv)
{
PrintFullPath(".\\");
Mat edges;
VideoCapture cap;
try
{
cap.open(0); // open the default camera
}
catch (...)
{
cout << "error!!" << endl;
}
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
edges = frame;
GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
//Canny(edges, edges, 0, 30, 3);
//Sleep(2000);
imshow("edges", edges);
if (waitKey(30) >= 0) break;
}
return 0;
}
the program crashes ONLY when the debugger is attached, when i press f5 it crashes in line "cap.open(0)", but when I press cntrol f5 it runs perfectly.
the error i get is:
Unhandled exception at 0x09068EFB in opencv_1.exe: 0xC0000005: Access violation executing location 0x09068EFB.
im using visual studio 2013, windows 8.0, opencv 3.0.
if i run the exe file in the command line the prorgam runs perfectly.
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)*;
}
}
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include "opencv2/opencv.hpp"
#include <opencv2/highgui.hpp>
#include <iostream>
#include <Windows.h>
#pragma comment(lib, "vfw32.lib")
#pragma comment( lib, "comctl32.lib" )
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat edges;
VideoCapture cap;
try
{
cap.open(0); // open the default camera
}
catch (...)
{
cout << "error!!" << endl;
}
if (!cap.isOpened()) // check if we succeeded
return -1;
namedWindow("edges", 1);
for (;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
edges = frame;
GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
imshow("edges", edges);
if (waitKey(30) >= 0) break;
}
return 0;
}
when i try to run this code in the command line it runs perfectly, but when i try to debug it in visual studio express 2013 it crashing at the line "cap.open(0);"
the errror is :
Unhandled exception at 0x0C028EFB in opencv_1.exe: 0xC0000005: Access violation executing location 0x0C028EFB.
i dont know what the problem is or how to fix it.
sorry for bad english
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.
Which OpenCV's function support the analog camera for live streaming?
Please give me the answer.
I tried CvCapture and VideoCapture functions of OpenCV.
It works for USB camera but did not work for Analog camera.
I tried VideoInput function.It works well with analog camera but i want opencv inbuilt function.
So please help me.
Thanks for your time.
This is the code for cvcapture function which I have used.
#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "videoInput.h"
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
char key;
int main()
{
cvNamedWindow("Camera_Output", 1); //Create window
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY); //Capture using any camera connected to your system
while(1){ //Create infinte loop for live streaming
IplImage* frame = cvQueryFrame(capture); //Create image frames from capture
cvShowImage("Camera_Output", frame); //Show image frames on created window
key = cvWaitKey(10); //Capture Keyboard stroke
if (char(key) == 27){
break; //If you hit ESC key loop will break.
}
}
cvReleaseCapture(&capture); //Release capture.
cvDestroyWindow("Camera_Output"); //Destroy Window
return 0;
}
end of code
Next code is using VideoInput function.
The code is
#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "videoInput.h"
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main(int, char**)
{
videoInput VI;
int numDevices = VI.listDevices();
//int device1= 0;
VI.setup(0);
unsigned char* yourBuffer = new unsigned char[VI.getSize(0)];
IplImage* colourImage = cvCreateImage(cvSize(320,240),8,3);
while(1)
{
VI.grabFrame(0, yourBuffer);
colourImage->imageData = (char*)yourBuffer;
cvConvertImage(colourImage, colourImage, 3);
cvShowImage("test",colourImage);
if( cvWaitKey(10) == 27)
break;
}
return 0;
}
end of code
and last code is using videocapture function
the code is
#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "videoInput.h"
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main() {
VideoCapture stream1(-1); //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";
return 0;
}
//unconditional loop
while (true) {
Mat cameraFrame;
stream1.read(cameraFrame);
imshow("cam", cameraFrame);
if (waitKey(30) >= 0)
break;
}
return 0;
}
End of code
Please help me.
I am trying to connect my camera with opencv, but window is showing a grey output screen with no image and output window of vc++ is showing the following error:
... 'opencv practice.exe': Loaded 'C:\Windows\SysWOW64\msyuv.dll',
Cannot find or open the PDB file 'opencv practice.exe': Unloaded
'C:\Windows\SysWOW64\msyuv.dll' ...
i tried fining the msyuv.dll, and it is available there.
i have one further question, next to this, i want to implement this on unity3d, so should i stick with opencv or use emgucv?
#include "StdAfx.h"
#include <stdio.h>
#include <stdlib.h>
#include <opencv\cvaux.h>
#include <opencv\highgui.h>
#include <opencv\cxcore.h>
using namespace std;
int main(int argc)
{
CvCapture* cam = NULL;`
cvNamedWindow("hi",CV_WINDOW_AUTOSIZE);
IplImage* img = NULL;
cam = cvCaptureFromCAM(-1);
char a;
while(1)
{
if(cam != NULL)
{
img = cvQueryFrame(cam);
}
else
{
printf("erro1");
return -1;
}
cvShowImage("hi", img);
a = cvWaitKey(20);
if(a == 27)
break;
}
cvReleaseCapture(&cam);
cvDestroyAllWindows();
return 0;
}