videocapture opencv (ubuntu 13.10, opencv 2.4.8) - c++

when i tried to work with a video file i can't seem to open the file
when i test on isOpen() it gives me thats it did not open
what did i already check:
videofile working and in correct path
rebooting
reinstalling ffmpeg (with diferent configurations)
my code:
VideoCapture readVideo;
readVideo.open(argv[1]);
Mat frame;
if(!readVideo.isOpened()){
fprintf(stderr,"video niet geladen 0 \n");
return 2;
}
Example of the file i give in argv[1]:
out.avi (mpeg4 codex)
it works on someone elses setup so i know its not the code

The problem seemed to be with the installation of the ffmpeg that wasn't compleetly linked to the instalation of opencv, installed bouth again and worked like a charm

Related

OpenCV cannot open video file

I use
cv::VideoCapture video(mp4name);
But
video.isOpened()==false;
I use OpenCV 3.4.1.
Any ideas?
Thanks,
Yair

Opencv raspberry pi 3 video play c++

Im currently working on video processing project on raspberry pi 3 using OpenCV libraries. As a guide im reading opencv2 computer vision application programming cookbook. If you are familiar with this book, it explains everything on windows visual studio. But im able to compile things using cmake. And everything works fine.
#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
int main()
{
// Open the video file
cv::VideoCapture capture("../bike.avi");
// check if video successfully opened
if (!capture.isOpened()){
std::cout<<"Error loading video!.."<<std::endl;
return 1;
}
// Get the frame rate
double rate= capture.get(CV_CAP_PROP_FPS);
bool stop(false);
cv::Mat frame; // current video frame
cv::namedWindow("Extracted Frame");
// Delay between each frame in ms
// corresponds to video frame rate
int delay= 1000/rate;
// for all frames in video
while (!stop) {
// read next frame if any
if (!capture.read(frame))
break;
cv::imshow("Extracted Frame",frame);
// introduce a delay
// or press key to stop
if (cv::waitKey(delay)>=0)
stop= true;
}
// Close the video file.
// Not required since called by destructor
capture.release();
}
In the book writer uses this code. And i know this code works on linux windows etc but not on raspberry pi. I changed bike.avi with a video that i recorded with raspicam. raspivid -o bike.h264 -h 620 -w 480 -fps 15. But i still get Error loading video!...
Ps: i can play bike.avi video that i downloaded from books website via vlc player using ssh -X.
My CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8)
project(salt)
FIND_PACKAGE(OpenCV REQUIRED)
add_executable(a.out main.cpp)
TARGET_LINK_LIBRARIES(a.out ${OpenCV_LIBS})
I figured out the problem. OpenCV with usb webcams work fine on raspberry pi. But when it comes using raspverry pi camera, its not supported. That is why some developers created RaspiCam libraries which works together OpenCV. They even provide cmake configurations. I installed it and capturing video around 25fps working great. This solution is for C++ users. If u are coding with python, just search python raspberry pi camera OpenCV.

VideoCapture::read always returns false

I'm running OS X El Capitan and trying to use OpenCV VideoCapture to read an .avi file. I've tried it on both opencv 2.4.1 and 3, both of which have the same outcome.
cv::VideoCapture capture("filename.avi");
cv::Mat currentFrame, prevFrame;
bool capPrevSuccess = capture.read(prevFrame);
bool capCurrSuccess = capture.read(currentFrame);
I've verified that the filename.avi is in the current working directory and I don't see any errors in the console.
I'm beginning to wonder if it's something with my machine. I have a similar problem running VideoReader in MATLAB on the same machine. I believe MATLAB uses OpenCV VideoReader as well, perhaps they're connected.
Error using VideoReader/init (line 619) Failed to initialize internal
resources.
Error in VideoReader (line 172)
obj.init(fileName);
EDIT: Looks like this has something to do with the video files I'm using. I downloaded an mp4 video, and had no trouble with it. Unfortunately I need to use the video files I'm using (all .avi), yet they all seem to not work with VideoCapture.

Issue with running open CV face detection on Mac mountain lion

I ran into an issue getting the standard open CV face detection (facedetect) working. The web cam light comes on but noting happens, the program is launched with a tiny sized window like this:
I am working from an excellent blog post and sample code. Here I what I have done:
Install OpenCV & get OpenCV source
brew tap homebrew/science
brew install --with-tbb opencv
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.6/opencv-2.4.6.tar.gz
tar xvzf opencv-2.4.6.tar.gz
Run the facedetect sample with the standard classifier.
cd ~/opencv-2.4.6/samples/c
chmod +x build_all.sh
./build_all.sh
./facedetect --cascade="../../data/haarcascades/haarcascade_frontalface_alt.xml"
I can modify the C++ sample code and recompile and run, but I have no idea what the issue is.
Does anyone have a suggestion?
Update The issue is the image from cvQueryFrame is empty:
IplImage* iplImg = cvQueryFrame( capture );
frame = iplImg;
if( frame.empty() )
{
cout << "FRAME EMPTY\n"; // This is getting logged
break;
}
Update: It works ok when the source is a static image, so the issue is something related to the webcam source.
You can try to localise the problem, did you try to capture an image from the and web cam show it, without running any other operation?
It seems there is a problem capturing image from the web cam via OpenCV, this kind of problems may happen due to hardware, for instance on my friends macbook pro captured image was 320x240 and on mine it was 640x480. My friend just changed a simple configuration from settings of the camera and his problem was solved. Your problem might be something like this.
Or you can try to run face detector just with some images, you need to change the code such that it loads an image from your disk and try to detect face on them. If it doesn't work that way either we can say that your problem is not camera, there is a bigger issue, or if it works we can surely say that the problem is web cam.
EDIT
If you are using IplImage type be sure to get couple more images from the camera, sometimes first image is empty.
This was due to a bug in OpenCV - its been fixed ( bug report here http://code.opencv.org/issues/3156) , but the version in homebrew/science is from before the fix.
You can get install a newer version by editing the brew formula for opencv ( based on this pull request https://github.com/Homebrew/homebrew-science/pull/540 )
edit /usr/local/Library/Formula/opencv.rb , and replace these lines:
url 'http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.6.1/opencv-2.4.6.1.tar.gz'
sha1 'e015bd67218844b38daf3cea8aab505b592a66c0'
with these ones
url 'https://github.com/Itseez/opencv/archive/2.4.7.1.tar.gz'
sha1 'b6b0dd72356822a482ca3a27a7a88145aca6f34c'
Then do
brew remove opencv
brew install opencv
Works on Mavericks (for me at least), should work on Mountain Lion
UPDATE: the version of OpenCV in homebrew/science has now been updated, so this answer is now out of date!
brew upgrade opencv
will make homebrew get the latest version, with fixed webcam capture.

Possible bug in OpenCV2.4 capturing frames from video

Could it be that there is a bug in OpenCV2.4 highgui for capturing frames from video in windows?
I installed both the precompiled libraries, the ones compiled by me, I can compile everything perfectly and I can run my programs if
they are image based. The problem is only for videos. OpenCV crashes in this function always:
virtual IplImage* retrieveFrame(int)
{
unsigned char* data = 0;
int step=0, width=0, height=0, cn=0;
if(!ffmpegCapture ||
!icvRetrieveFrame_FFMPEG_p(ffmpegCapture,&data,&step,&width,&height,&cn)) <-------CRASHES HERE
return 0;
cvInitImageHeader(&frame, cvSize(width, height), 8, cn);
cvSetData(&frame, data, step);
return &frame;
}
This is inside the class cap_ffmpeg.cpp and is called by VideoCapture.
I tried versions 2.4.2 and 2.4.9. My programes were working finde with opencv2
More information
Windows 7
Build the projects with cmake (important as it could be that cmake is not building/finding the right codecs)
VisualStudio 9 2008
OpenCV 2.4.2
EDIT
It looks like it is actually a bug, so, how can I solve this problem and change my code to be able to read avi files?
As a temporary solution I decided to re-encode the videos so OpenCV doesn't use the ffmpeg. I used VirtualDub with the microsoft video 1 compression, which uses "msvidc32.dll" driver.
It works with all my videos so it is enough by now as I can keep working with OpenCV in windows.
I had similar problem. I downloaded VirtualDub, but it did not open one of my avi video because of its FMP4 encode. So in the end, the solution that solved the problem was to install ffdshow, a decoder for windows. See this link: http://www.moviecodec.com/video-codecs/fmp4-codec-with-virtualdub-45814/
Then I do not need to use VirtualDub anymore to re-encode my video anymore!
if your using x64. Please use opencv_ffmpeg245_64.dll this solves may solve the problem. Or rename opencv_ffmpeg245_64.dll to opencv_ffmpeg245.dll may solve the problem.