I am getting video frames using cvQueryframes, but in few videos of avi file I get :
Unhandled exception at 0x715c14f0 0xC0000005:
Access violation reading location 0x02f509f0.
I am using visual studio 2010 with OpenCV 2.4.5 and Qt5
CvCapture* cap= cvCaptureFromFile(file);
frame = cvQueryFrame(capture);
There could be multiple reasons for this, link wrong file name, codec not found etc. Try putting debug printf before opening file to see if file name is proper also check for cap if it is not NULL. You can try something like this
int main(int argc, char*argv[])
{
char *my_file = "C:\\vid_an2\\desp_me.avi";
std::cout<<"Video File "<<my_file<<std::endl;
cv::VideoCapture input_video;
if(input_video.open(my_file))
{
std::cout<<"Video file open "<<std::endl;
}
else
{
std::cout<<"Not able to Video file open "<<std::endl;
}
namedWindow("My_Win",1);
namedWindow("Segemented", 1);
Mat cap_img;
for(;;)
{
input_video >> cap_img;
imshow("My_Win", cap_img);
waitKey(0);
}
return 0;
}
Related
#include <iostream>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace std;
// Driver code
int main(int argc, char** argv)
{
//----- COMMAND LINE -----
const String& filename = argv[1];
Mat image = imread(argv[1]);
//----- EXPLICIT WAY -----
//const String& filename = "C:/Users/letto/OneDrive/Things/sonoio.jpg";
//Mat image = imread(filename);
// Error Handling
if (image.empty()) {
cout << "Image File "
<< "Not Found" << endl;
// wait for any key press
cin.get();
return -1;
}
// Show Image inside a window with
// the name provided
imshow("Window Name", image);
// Wait for any keystroke
waitKey(0);
return 0;
}
With the code above I'm trying to open an image.
There are two ways I'm trying to do it:
COMMAND LINE: I pass the image url as a command;
EXPLICIT WAY: I write explicitly the image url.
The second method works perfectly.
With the first method I get this exception:
Exception thrown at 0x00007FFAC1FFF551 (ucrtbased.dll) in OpenImg.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
I'm using Visual Studio Code 2022 so this is the way I'm passing the url through the command line:
Where is the error? Help me find out please, thanks!
You have set - according to the image attached - additional command line arguments to the compiler and not to the app you run.
To add command lines to the app, right click on the project (OpenImg) and choose Debugging -> Command Arguments.
(And, as mentioned by #user4581301, verifying that the argument exists by checking args would've showed that accessing argv[1] would've been out of bounds. Its a good habit to learn.)
I build OpenCV 3.4 with Gstreamer MSVC 1.16.1, using Cmake and Visual Studio 10.
I have include bin directory to the system path variable, added all additional include and library to Visual Studio.
Now when I am trying to read an Image to test if OpenCV is correctly installed it throws an error as:
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file .../opencv/modules/highgui/src/window.cpp
The code was:
Mat image1;
image1 = imread("D:\\Capture2.JPG");
if(! image1.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
}
imshow("Image",image1);
cvWaitKey(0);
return 0;
Now I tried to play a video using demo code from openCV site:
// opencv_3.4_test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
// Create a VideoCapture object and open the input file
// If the input is the web camera, pass 0 instead of the video file name
VideoCapture cap("Wildlife.mp4");
// Check if camera opened successfully
if(!cap.isOpened()){
cout << "Error opening video stream or file" << endl;
return -1;
}
while(1){
Mat frame;
// Capture frame-by-frame
cap >> frame;
// If the frame is empty, break immediately
if (frame.empty())
break;
// Display the resulting frame
imshow( "Frame", frame );
// Press ESC on keyboard to exit
char c=(char)waitKey(25);
if(c==27)
break;
}
// When everything done, release the video capture object
cap.release();
// Closes all the frames
destroyAllWindows();
return 0;
}
The program is building correctly but I am getting following error while running it:
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:808)
warning: ?Wildlife.mp4 (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:809)
GStreamer: error opening bin syntax error
Where can be the error as they both are simplest OpenCV program.
So the error was, there was an invisible character ('\u202A') present just after " of the filename. Once I deleted it, everything runs fine.
I found this from the warning C4566: character represented by universal-character-name '\u202A' cannot be represented in the current code page (1252)
As I am completely new to OpenCV, I tried following a tutorial to capture video from a webcam. I used the following code:
#include "opencv2\opencv.hpp"
#include <stdint.h>
using namespace cv;
using namespace std;
int main(int argv, char** argc) {
Mat frame;
VideoCapture vid(0); //0 if we only have one camera
if (!vid.isOpened()) { //check camera has been initialized
cout << "ERROR: Cannot open the camera";
return -1;
}
while (vid.read(frame)) {
imshow("webcam", frame);
if (waitKey(30) >= 0) break;
}
return 0;
}
When I run the program, a window that shows the video feed opens, but it then almost immediately closes. I get this snippet from the Debug output:
SETUP: Device is setup and ready to capture.
Event: Code: 0x0d Params: 0, 0
Event: Code: 0x0e Params: 0, 0
Exception thrown at 0x000007FEFCBAA06D in test.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000026EB10.
SETUP: Disconnecting device 0
I don't know what could be wrong with my code or even how to begin debugging this. Any advice? Thank you!
I am compiling on Ubuntu 14.04 using OpenCV 3.1. When trying to open a video file it gives this error:
"Cannot open the video file"
I installed everything i could install : ffmpeg etc. Haven't found a solution checking out similar questions on StackOF.
What do ?
cv::VideoCapture cap(argv[1]);
Where argv[1] is the file name in the same directory as the executable.
In case your constructor is failing, you may want to use the .open() method. So, if you want to open a file that is called "myVideo.mp4" that is in the folder of your project, you would do the following:
cv::VideoCapture cap;
cap.open("myVideo.mp4");
For more detailed informations about this method, check this documentation link
Also, the book Learning OpenCV 3, from the O'Rilley media, on page 26 gives you a good example. Here is a Gist that I made to give you as an example.
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
int main() {
cv::VideoCapture cap;
cap.open("myVideo.mp4" );
cv::namedWindow( "myVideo", cv::WINDOW_AUTOSIZE );
cv::Mat frame;
while(true) {
cap >> frame;
if( frame.empty() ){
std::cout << "Could not load the video frames. \n";
break;
}
cv::imshow( "myVideo", frame );
if( cv::waitKey(27) >= 0 ){
std::cout << "Escape pressed \n";
break;
}
}
return 0;
}
I use this code and it just displays the video into a frame but when I execute this code I gets this Unhandled exception.
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace cv;
int main()
{
Mat image;
VideoCapture cap;
cap.open(0);
namedWindow("Window",1);
while (1)
{
cap>>image;
imshow("Window",image);
waitKey(100);
}
return 0;
}
Unhandled exception at at 0x00007FFF945FAB78 in ConsoleApplication2.exe: Microsoft C++ exception: cv::Exception at memory location 0x00000099DFC1F3B0.
What can I do to escape from this unhandled exception & display the video correctly?
Note : Using OpenCv 2.4.8 , V.S.2012 x64
check VS dependencies,
project/projectname configuration/ linke/input
in address check lib name.