OpenCV2.4.2 unhandled exception on VideoCapture - opencv

I just installed OpenCV2.4.2 and created an OpenCV project using CMake. I don't get any compilation errors. I have several functions for processing images and I have 2 applications:
1- Processes data from a video
2- Processes simulated data.
Both applications are identical except from the data extraction from the video.
PROBLEM: The application processing video crashes with
Unhandled exception at 0x75d8a048 in program.exe Access violation
reading location 0x049f08c0.
It crashes in this part of the code, when reading frames:
cv::VideoCapture _video;
while(1)
{
// grab the frame
_video >> frame; <-------------CRASHES HERE
processFrame(frame);
}
So I guess there could be a problem with cv::VideoCapture class in OpenCV 2.4.2. How can I detect the problem and solve it?
EDIT
With video camera I managed to catch the error message:
OpenCV Error: Assertion failed (m.dims >= 2) in unknown function, file ..\..\..\
src\opencv\modules\core\src\matrix.cpp, line 268
OpenCV Error: Assertion failed (0 <= _rowRange.start && _rowRange.start <= _rowR
ange.end && _rowRange.end <= m.rows) in unknown function, file ..\..\..\src\open
cv\modules\core\src\matrix.cpp, line 283

Are you checking if the capture actually opened the file/camera ?
if(_video.isOpened()) { // check if capture succeeded
// do stuff
}
Not all codecs are supported per default. This depends on the library you use underneath to open the video. (This might be ffmpeg or quicktime).
Also you can catch the exception yourself, just to be on the safe side for future problems
try {
_video >> frame;
} catch (cv::Exception) {
cout << "An exception has accurred" << endl;
};

Related

SensorStreamViewer, HoloLensForCV : "Failed to initialized media capture: Access is denied."

I tried to get sensor stream from HoloLens, so I used the HoloLensForCV.
(https://github.com/Microsoft/HoloLensForCV)
First, I checked that SensorStreamViewer project works, but few days later, I updated HoloLens and then it doesn't work. The error I receive is Access is Denied
HoloLens Camera view capture
HoloLens Privacy Camera capture
The Webcam capability in VS capture
And, I guess the error occurs in this part(SensorStreamViewer.xaml.cpp).
// Initialize MediaCapture with the specified group.
// This must occur on the UI thread because some device families
// (such as Xbox) will prompt the user to grant consent for the
// app to access cameras.
// This can raise an exception if the source no longer exists,
// or if the source could not be initialized.
return create_task(m_mediaCapture->InitializeAsync(settings))
.then([this](task<void> initializeMediaCaptureTask)
{
try
{
// Get the result of the initialization. This call will throw if initialization failed
// This pattern is docuemnted at https://msdn.microsoft.com/en-us/library/dd997692.aspx
initializeMediaCaptureTask.get();
m_logger->Log("MediaCapture is successfully initialized in shared mode.");
return true;
}
catch (Exception^ exception)
{
m_logger->Log("Failed to initialize media capture: " + exception->Message);
return false;
}
});
When I start others project like 'ComputeOnDevice', I can see an alert message window asking me allow to access camera. However, when I start 'SensorStreamViewer', I didn't see any alert message asking about camera access.
I started debugging, and confronted this error message.
Exception thrown at 0x772C3332 in SensorStreamViewer.exe: Microsoft C++ exception: Platform::AccessDeniedException ^ at memory location 0x0180E680. HRESULT:0x80070005 Access is denied.
WinRT information: The required device capability has not been declared in the manifest.
How can I solve this problem?
In your Package.appxmanifest file, you need to add the following capability.
<rescap:Capability Name="perceptionSensorsExperimental" />

opencv videocapture fail to read frame from rtsp

I'm getting and error with read frame from rtsp stream of hikvision camera.
Here is my code to read:
public void readImage(){
VideoCapture capture = new VideoCapture(streamUrl);
if(capture.isOpened()){
Mat frame = new Mat();
while(true){
if(capture.read(frame)){
System.out.println("frame read");
}else{
System.out.println("failed to read frame");
}
}
}
}
with above code i can read frame successfully if the resolution of image from stream is low ex (704x576) but if i resolution is hight or i run some parallel task then the capture fail to read frame. After capture has failed in first read loop then i terminate all other task then capture still fail to read unless i recreate another capture (recreate capture object). What should i do now? (this happen on both open cv2.4 and open cv3.2 when i try )
You may want to release memory after use.
Put the code frame.dispose(); after the end of the while loop

getting error like unhadler (kernelbase.dll) openCV using C++

I am doing simple program to detect webcam, it runs for some time but than I am getting the error message.
i took the code from,
https://thefreecoder.wordpress.com/2012/09/11/opencv-c-video-capture/
Unhandled exception at 0x74f22f71 (KernelBase.dll) in cvtest.exe: Microsoft C++ exception: cv::Exception at memory location 0x0109f524..
how to solve this problem.
Thank you very much in advance.
You could put the entire code within the try catch block
try
{
// ... Contents of your main
}
catch ( cv::Exception & e )
{
cout << e.msg() << endl;
}
This might help you! or Try with the debugger which line cause the exception.

Receiving "End of file" while streaming RTSP on iOS

I'm using ffmpeg library to stream RTSP from an IP camera in the local network. The streaming is working fine with the code.
The only problem is that the stream seems to stop after some time. On further debugging I found out that I'm receiving an "End of file" and thats why the loop is breaking.
while(!playerShouldStop)// && (av_read_frame(pFormatCtx, &pkt1)>=0))
{
int ret = av_read_frame(pFormatCtx, &pkt1);
NSLog(#"av read frame returned = %s",av_err2str(ret));
if(ret >= 0)
{
// process video
}
else
break;
}
Logs says
av read frame returned = End of file
I downloaded Wireshark to check what RTSP packets I'm getting but no help there.
First of all is it normal to receive EOF in a live stream (which is not supposed to end).
Secondly, calling av_read_frame() again and again is not helping either, but when I restart the entire method ( right from avformat_open_input ) then it works. Just that the streaming isn't smooth and comes to a pause every now and then.
Ok...it seems to be working without EOF when i open the stream with AVDictionary options.
AVDictionary *opts = 0;
int ret = av_dict_set(&opts, "rtsp_transport", "tcp", 0);
// Open video file and read header information into pFormatCtx
if (avformat_open_input(&pFormatCtx, filename, NULL, &opts) != 0)
{
NSLog(#"Error opening video file.");
return;
}
av_dict_free(&opts);
Still, any proper explanation to this would be helpful.
I have met same question about av_read_frame return EOF(End Of File) while decoding realtime stream. Finanlly I found that when this problem appears. It's Because I set the AVFormatCtx.interrupt_callback.callback, and the number of timeout is too small(this call back can prevent av_read_frame() blocking). So When The callback return, av_read_frame() return EOF. Hope this question I met may help you.

cvSetErrMode not working

I'm trying to use Parent mode in OpenCV. It seems that OpenCV is ignoring the cvSetErrMode() call.
fprintf(stderr, "cvSetErrMode(%d) returned %d\n",
CV_ErrModeParent, cvSetErrMode(CV_ErrModeParent));
fprintf(stderr, "cvGetErrMode() returned %d\n", cvGetErrMode());
This returns:
cvSetErrMode(1) returned 0
cvGetErrMode() returned 0
It seems to me that cvGetErrMode() should return 1.
These functions are deprecated in OpenCV 2.x OpenCV still provides stub implementation for backward compatibility.

Resources