OpenCV: Couldn't read video stream from file - c++

I'm trying to output a video from file using OpenCV 3.4.0. Xcode gives an error message: OpenCV: Couldn't read video stream from file. When i capture video from cam xcode run successfull. I try install ffmpeg 3.4.1 and don't know what headers i need to include. It's all on OSX 10.12 Sierra

Found solution, i point wrong path to file "~/Desktop/test.mp4" just changed to "/Users/jameson/Desktop/test.mp4" apparantly opencv not enough abridged version of path

Related

OpenCV C++ does not load ANY video on Ubuntu 16.04 under VideoCapture

I installed OpenCV 2.4.13 after installing the required dependencies and I'm running it with Qt Creator 5.7 for programming in C++. Following some tutorials I managed to load still images, process them and so on. But when I try to use the cv::VideoCapture, for example:
cv::VideoCapture cap;
cap.open("<File location/file name>");
or:
cv::VideoCapture("<File location/file name");
cap.isOpened() always return false. Even if I try to ignore this and go further with Mat, read, imshow and so on, the program crashes. I've already tried everything about loading the file: giving a std::string as argument, giving a *char, putting the video file on easier locations, in the project directory and nothing works. I tried with two different .mp4, with a .mov and with the cube4.avi file given in the "samples" folder (from openCV examples). All these files are perfectly played by my VLC. I've already tried in Qt with a QtWidgets project and with a plainCpp project. It never works. After searching about it, I've seen that this bug is very recurrent, but I've just found solutions for Windows, regarding on adding a .dll file to the project. But what should I do on Ubuntu, since Linux uses no dlls?
I figured out how to solve this and I'm here to share with everyone who encounter similar problems. First of all, my FFmpeg installation was for any unknown reason ignored on the OpenCV compilation. Since FFmpeg is needed to read and write videos, OpenCV wasn't able to do these jobs and displayed no error or warning messages about that. Anyway I decided to try everything again from the beginning. Keep in mind: if you just reinstall FFmpeg, it's not going to solve your problems; after that you have to do cmake, compile and install OpenCV again. I downloaded the most recent version of FFmpeg from the repository, compiled and installed it again. I tried to compile OpenCV again, but it was always stuck at about 15% when processing a FFmpeg (Libav) .h file with the message:
<file_name.h> can not be used when making a shared object; recompile with -fPIC
So I searched for it and with some effort I found out that it was necessary to compile the FFmpeg with the following configure line before doing the make:
.\configure --enable-pic --enable-shared
Some ffmpeg installation tutorials include even more commands after "configure". Then I compiled and reinstalled FFmpeg and compiled and reinstalled OpenCV. After that, I was able to load videos (the cap.isOpened() was no longer false), but nonetheless I was getting the following error for any video and they weren't being read:
Assertion desc failed at libswscale/swscale_internal.h:674
The way I found to solve this was downloading the newest stable FFmpeg version instead of the newest on, compiling it again, compiling OpenCV again and then it was successful! Now I can both load and write video files (I haven't tested it with multiple codecs yet). I wonder why they don't launch pre-compiled versions of OpenCV with everything so that we don't need to deal with all these stuffs...
Summarizing everything:
Download the last stable release of FFmpeg. If it doesn't work, try an older one. (I'm using the 2.8.6, the last stable right now).
Unpack it, open the terminal from the ffmpeg folder, compile and install it typing:
.\configure --enable-pic --enable-shared
make
sudo make install
Download OpenCV (if you haven't done it yet), unpack and install it following the official linux installation tutorial:
http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation
I solve the problem by install "opencv3.2.0-dev" instead "opencv3.2.0";
pip install opencv-python is not enough to install OPENCV.

OpenCV (C++) Can't get XVID video file framerate

I'm trying to get VideoCapture working with OpenCV. The video I'm trying to load is in XVID format (checked it with VideoCapture::get(CV_CAP_PROP_FOURCC)). It works fine, but whenever I try to get the video framerate (VideoCapture::get(CV_CAP_PROP_FPS)) I get -nan.
I've used the same video and the same code on another computer (at uni, they have a custom Debian installation) and I can confirm that the framerate info is there (it works fine there). I read somewhere that Ubuntu recently removed ffmpeg from their repositories (I use Linux Mint 17.2), so I installed the ffmpeg package from the ppa:kirillshkrogalev/ffmpeg-next repositories. After that I recompiled OpenCV and installed again, without any change.
I'm using OpenCV 2.4.11 with C++ under Linux Mint 17.2.
Probably XVID is missing on your linux machine which is required by ffmpeg. Try installing XVID as below, it may help you.
cd /opt
wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
tar xzvf xvidcore-1.3.2.tar.gz
cd xvidcore/build/generic
./configure --prefix="$HOME/ffmpeg_build"
make
make install

OpenCV imgcodecs.hpp file not found error

I'm trying to compile a C++ program that uses OpenCV to score the similarity of two images:
Image Histogram Compare
When I g++ compile the file:
'opencv2/imgcodecs.hpp' file not found
#include "opencv2/imgcodecs.hpp"
I updated the opencv formula on Mac OS X. I re-ran brew install, but I still get this error.
mdfind imgcodecs.hpp -name
returns nothing - the file is nowhere on my system.
Does anyone know my imgcodecs is not included, and how to include it? I'm really novice at C and OpenCV, and enormously grateful for any help.
I notice that you are looking at tutorial code on the master branch (aka 3.0.0). It uses an imgcodecs module that is not present in earlier versions of OpenCV (e.g. 2.4.9).
Check which version of OpenCV you have (it seems not 3.0.0) and use a matching version of tutorial code (e.g. OpenCV 2.4.9 Histograms_Matching/EqualizeHist_Demo.cpp)

OpenCV VideoCapture not read any video File in Windows 7 32bit

i try to read .avi or .mpeg video file using VideoCapture class of OpenCV2.4.8 in C++ using QtCreator and CMake 2.8.12.1.
Before built OpenCV, i download FFMPEG static version and put them into Program Files directory, i add their path into enviroments variable PATH, then i download K Lite Codec Pack Full, install it and only then i built OpenCV with CMAKE and mingw provide by Qt. After installation i add to PATH the right path of built OpenCV.
The stream from webcam works fine, but the stream from a video file doesn't work. I tried on Windows 7 32bit and Windows 8 64bit.
Here is the code
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include "opencv2/opencv.hpp"
cv::Mat img;
cv::VideoCapture cap("Prova.avi");
std::cerr << cap.isOpened() << std::endl;
while(cap.read(img)){
cv::imshow("Opencv", img);
cv::waitKey(33);
}
The same code works on Ubuntu 12.04 with the same version of OpenCV and with the ffmpeg build by myself.
What is wrong?
Download the file opencv_ffmpeg.dll. I got it from this
Now rename the opencv_ffmpeg.dll according to the opencv version you are using. For OpenCv 2.4.8 rename it as opencv_ffmpeg248.dll and add the location of this file to the PATH in environment variable. Now try to run your program.
For some unknown reason in a system 32bit the building created a dll called opencv_ffmpeg248_64.dll and the installation of opencv was in a folder "x64", so i think that dll was for 64bit system. I download the pre built version of openCV and i use the dll included in that package.

How do I let OpenCV know codecs exist in non-standard locations?

I'm working with OpenCV on an HPC cluster that does not have any video codecs. I was able to install Xvid in my home directory but now I don't know how to tell OpenCV where they are in order to open video files with VideoCapture.
Thanks for your help.