OpenCV: VideoCapture not working with DSHOW backend - opencv

I built OpenCV (with mingw 4.9.2 # Win7Prof64) with
CMake switches for WITH_FFMPEG and WITH_DSHOW turned on.
When I access a movie file with VideoCapture (fileName) works fine (it uses ffmpeg backend then).
But VideoCapture (fileName, cv::CAP_DSHOW) doesn't work
(isOpened() returns false).
What is missing/ what do I do wrong?
Are there any kind of dshow libs/ dlls needed?

As to my duplicate in opencv forum ... cv::CAP_DSHOW is not implemented for files.

Related

OpenCV - RTSP stream not opening

I have a RTPS streaming camera. The stream works fine when I test it with VLC:
vlc -vvv rtsp://192.168.0.23:554/stream
However with openCV it does not open:
cv::VideoCapture capture;
bool ok = capture.open("rtsp://192.168.0.23:554/stream");
returns false.
What can be the reason?
I had a similar problem. In my case the dll starts with "opencv_ffmpeg" was missing in the run path.
If you are using OpenCV 4+ you need to copy the ffmpeg related dll and paste it next to your executable. For example I've built my OpenCV with the BUILD_opencv_world option and I have a file named opencv_videoio_ffmpeg430_64.dll in my bin folder in the my build directory. Without that file it won't open the stream and shows nothing.
When using the VideoCaptuer class with OpenCV 4, in C++, it does not work with RTSP streams.
you can do it by OpenCV and python as below:
import cv2
str1=cv2.VideoCapture("RTSP Address")
while True:
_,frame=str1.read()
cv2.imshow('SOMENAME',frame)
s=cv2.waitkey(0)

Opencv 3.1 compiled with FFMPEG, but won't open https urls

I work on a 16.04 system, and have successfully installed opencv 3.1 with FFMPEG flags enabled. I double checked this was actually the case by cv2.getBuildInformation() and I got FFMPEG = YES.
I am trying to open a video that is hostel on a private server by my workplace (I am logged in to the VPN, in case thats a concern) and I can access this video over the browser. But videocapture with cv2 fails.
>>> cap = cv2.VideoCapture("https://xxx.mp4", cv2.CAP_ANY) #dummy url
>>> cap
<VideoCapture 0x7f63300fa4b0>
>>> cap.isOpened()
False
This is always the case for https urls. It seems to be able to work with local videos just fine. I have tried a bunch of different thing: initially thought it was a gstreamer problem so I checked my plugins, had some gst-bad versions (ref: https://github.com/GStreamer/gst-plugins-ugly), removed those and replaced with good versions, no joy. Also tried to explicitly tell videoCapture to use cv2.CAP_ANY and cv2.CAP_FFMPEG flags while reading the video, still no luck.
I disabled the Gstreamer flag while compiling opencv, but even with it set to ON, there was no difference in my problem.
I haven't been able to find a solution to this issue and have been looking and trying different things for days now! Any ideas?
Eventually, I gave up on trying to install and reinstall opencv3.1, and switched to opencv 3.4.1. With that, and my current (as original question post) configuration for gstreamer and ffmpeg, I only had to create symlinks for libopencv_core.so.2.4 that gstreamer was looking for, and the rest of it worked fine.
Hope this helps someone!
I haven't managed to figure out what exactly was the issue with opencv3.1 (like I mentioned, that is the configuration my other colleagues have, and the functionality works just fine for them) but this is what I ended up doing after spending days on the issue.

OpenCV VideoCapture fails to load compressed video files when building with staticlib

I can embed OpenCV .DLLs and build my program in Visual Studio 2010, Debug mode, x64 platform using OpenCV 2.4.4 static libraries from C:\opencv244\build\x64\vc10\staticlib.
I use VideoCapture to load a video file and play it. Everything works fine when I open an uncompressed video file; But when I open a compressed video file (e.g. xvid), VideoCapture fails and can not load and open the video file. In this case if I put OpenCV .dll files near my program's .exe file, VideoCapture will work for the compressed video files too. But I have embedded OpenCV .dlls in the .exe file and I assume it has to be able to work fine without having OpenCV .dlls. Could you please let me know how can I resolve this issue?
Update:
Just now I noticed this issue will be resolved by only including opencv_ffmpeg244_64.dll near the program's .exe file. Other OpenCV .dlls will not be required to be present. So now the question will be: Is there any way to embed "opencv_ffmpeg244_64.dll" in the program's .exe file? (Albeith this one is not a big deal after all).

how can I use the openCV FFMPEG video I/O rather than the DirectShow one in Windows?

So I'm trying to write a video using the openCV videoWriter as such:
writer=cv.CreateVideoWriter(path+"test_output.avi",-1,fps,(W,H),1)
So instead of supplying the FOURCC I supplied -1 in order to see what codecs I have available.
Result was Microsoft RLE, Microsoft Video 1, Intel YUV, and Uncompressed.
The reason is that when configuring openCV using CMAKE for Visual Studio 10 x64, this is what I have in the video i/o:
Video I/O: DirectShow
Is there a way to switch this to FFMPEG? I know the ffmpeg dll is present in \3dparty\ffmpeg.
I looked for Cmake FFMPEG flags but found none whatsoever. The weird thing is in the CmakeLists.txt in the opencv root under the video section:
if(UNIX AND NOT APPLE)
<FFMPEG stuff>
elseif(WIN32)
status(" Video I/O:" HAVE_VIDEOINPUT THEN DirectShow ELSE NO)
endif()
So it seems to me that opencv automatically switched to DirectShow and gives no choice of using FFMpeg.
Or rather can one upgrade Driectshow to support other formats such as Divx or h264?
Any ideas?
The answer your looking for is here and it works for the 32 bit and 64 bit configurations. I used this build of FFMPEG. http://ffmpeg.zeranoe.com/builds/win64/dev/ffmpeg-git-1aeb88b-win64-dev.7z
1) Download OpenCV 2.3
2) Open the root CMakeLists.txt and insert the line set(HAVE_FFMPEG 1)
3) Download http://ffmpeg.zeranoe.com/builds/win64/dev/ffmpeg-git-1aeb88b-win64-dev.7z (or the 32 bit build if u fancy it)
4) Edit avformat.h found in the ffmpeg include dir with #define INT64_C
5) Edit cap_ffmpeg_impl.hpp from the highgui project with #define snprintf _snprintf
6) in your highgui project properties under C/C++>Additional Include Directories add path of the include directory of FFMPEG you just downloaded
7)On the same property page under Linker>General>Additional Library Dependencies add the path of the lib directory of FFMPEG you just downloaded
8)On the same property page under Linker>Input>Additional dependencies add ALL the names of the libraries of ffmpeg found in lib (avformat.lib, avscale.lib, avcore.lib etc)
9) build the highgui project
10) Add the path of the .dll files that came with FFMPEG to the System Path environment variable.
That's it! 10 easy steps ;)
If you're still unable to compile OpenCV with FFMpeg support, the library that is linked on this blogpost provides a pretty good starting point for creating a windows-compatible FFMpeg wrapper: Making OpenCV-2.3 work with ffmpeg library and Microsoft Visual Studio 2010

IplImage 'None' error on CaptureFromFile() - Python 2.7.1 and OpenCV 2.2 WinXP

I am running Python2.7.1 and OpenCV 2.2 without problems in my WinXP laptop and wrote a tracking program that is working without a glitch. But for some strange reason I cannot get the same program to run in any other computer where I tried to install OpenCV and Python (using the same binaries or appropriate 64 bit binaries). In those computers OpenCV seems to be correctly installed (although I have only tested and CaptureFromCamera() in the webcam of the laptop), but CaptureFromFile() return 'None' and give "error: Array should be CvMat or IplImage" after a QueryFrame, for example.
This simple code:
import cv /
videofile = cv.CaptureFromFile('a.avi') /
frame = cv.QueryFrame(videofile) /
print type(videofile) /
print type(frame)
returns:
type 'cv.Capture' /
type 'NoneType'
OpenCV and Python are in the windows PATH...
I have moved the OpenCV site-packages content back and forth to the Pyhton27 Lib\Site-packages folder.
I tried different avi files (just in case it was some CODEC problem). This AVI uses MJPEG encoding (and GSpot reports that ffdshow Video Decoder is used for reading).
Images work fine (I think): the simple convert code:
im = cv.LoadImageM("c:\tests\colormap3.tif")
cv.SaveImage("c:\tests\colormap3-out.png", im)
opens, converts and saves the new image...
I have tested with AVI files in different folders, using "c:\", "c:/", "c:\" and "c://".
I am lost here... Anyone has any idea of what stupid and noob mistake may be the cause of this? Thanks
It may sound stupid, but I just had the same issue with the same symptoms for the same code snippet (Python 2.7.1, Win 7, OpenCV 2.2.0). I changed file path from
capture = cv.CaptureFromFile('C:\Misc\tree.avi')
to
capture = cv.CaptureFromFile('C:/Misc/tree.avi')
and voila
<type 'cv.Capture'>
<type 'cv.iplimage'>
I was having this problem, and here is how I fixed it. I took a look at the output of OpenCV's cmake command, and it had the following line:
...
-- FFMPEG: NO
...
In order to fix this, you might be able to get away with simply installing the following libraries:
sudo apt-get install libavformat-dev libavcodec-dev libavfilter-dev libswscale-dev
Re-running cmake will hopefully now say:
...
-- FFMPEG: YES
...
Re-compile OpenCV, re-install it, and hopefully you can now read videos. If you still have problems, you can try to compile ffmpeg using the --enable-shared option, using these as guides:
http://opencv.willowgarage.com/wiki/FFMPEG
http://ubuntuforums.org/showthread.php?t=786095
Hope that helps.
This must be an issue with the default codecs. OpenCV uses brute force methods to open video files or capture from camera. It goes by trial and error through all sources/codecs/apis it can find in some reasonable order. (at least 1.1 did so).
That means that on n different systems (or days) you may get n different ways of accessing the same video. The order of multiple webcams for instance, is also non-deterministic and may depend on plugging order or butterflies.
Find out what your laptop uses, (re)install that on all the systems and retry.
Also, in the c version, you can look at the capture's properties
look for cvGetCaptureProperty and cvSetCaptureProperty where you might be able to hint to the format.
[EDIT]
Just looked i tup in the docs, these functions are also available in Python. Take a look, it should help.

Resources