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

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.

Related

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.

How to get imagemagick to support .flif and .bpg formats?

For quite some time now there have been several image codecs which provide significant improvements over PNG and JPG, however the latter still remain dominant.
Two formats in particular that I'd really like to see getting more adoption are FLIF and BPG. They seem superior in every possible way to JPG and PNG (except for lacking market acceptance). Especially FLIF seems extremely promising.
TL;DR = Besides supporting them in my own software, is there a way to get FLIF and BPG support in imagemagick?
The ChangeLog for ImageMagick says
2015-06-25 6.9.1-7 ... * Support BPG image format
There's no direct BPG support in the ImageMagick source code, but config/delegates.xml lists delegates "bpgdec" and "bpgenc" which convert BPG files to and from PNG files which then get processed by ImageMagick. You would have to supply those delegates if they aren't already on your system. You can download the sources for bpgdec and bpgenc from
http://bellard.org/bpg/
There's nothing about FLIF in the ChangeLog, but a "pull request" for FLIF support was recently applied, and coders/flif.c exists in the ImageMagick sources (it requires a separate libflif to work). You can download the source code for libflif from https://github.com/FLIF-hub/FLIF
I haven't tested either feature.
bpgdec, bpgen, and libflif are all LGPL-licensed, and a reduced version of bpgdec is available under a BSD license.
To get imagicmagick to work with .bpg you have to compile it separate from what is already there. In other words, you have to add it in. So download the source code and it doesn't compile. Give up and use something else or try this because I got it to work
use apt-get and install
libpng*
libsdl1*
libsdl2*
libsdl-image*
cmake
libjpeg*
and maybe libjpg*
decompress the .bpg files you downloaded and just
use the command
make and sudo make install
AFTER that imagemagick will work with libpg and will not give an error of a missing delegate..

Converting cpp file that uses opencv to mex file with matlab in ubuntu

I need some help converting a cpp file to a mex file.
I get the error below:
fatal error: opencv2/core/core.hpp: No such file or directory
Compilation terminated
The cpp file is using opencv header files. I'm not sure how to link Matlab with opencv in Ubuntu. I saw this link
http://xanthippi.ceid.upatras.gr/people/evangelidis/matlab_opencv/
but its for Windows and I'm not sure where Ubuntu stores opencv. There are a couple places I found opencv folders
usr/local/include/opencv and
usr/local/include/opencv2 and
usr/local/share/OpenCv
Tried these with OCVROOT but got 'Error: Unexpected Matlab Operator'. Not sure what I'm doing wrong here. Any help would be much appreciated.
Thank you!
Mex needs to be told where the OpenCV header files are. You can either fix it in ~/.matlab/R2013a/mexopts.sh or just put a -I argument on the mex command line. You will find the answer to How to link during Matlab's MEX compilation helpful.
You will have to sort out which of those OpenCV versions you want to use. Might be best to install you own so you know what you are dealing with.
'Error: Unexpected Matlab Operator' would be cause by an error in your matlab code.
matlab_opencv should work fine on Linux, the only windows specific thing about it the instructions, as far as I know.
unless you have a custom mexopts.sh, I don't think setting OCVROOT will hve any affect on Matlab.

OpenCV: reading frames from webcam hangs

I've been experiencing an issue with OpenCV lately which I wasn't able to google a solution for. Now I solved it and want to share the solution.
So I use OpenCV to work with a webcam in Linux. I built and installed OpenCV 2.4.2 and run my program. It opened the camera (the LED on it turned on) but it never got to read any frame from it. It freezes on the line
capture.grab();
It just never returns from that method. Also applies to the >> operator which uses grab() internally.
This happens only if I set desired frame width/height to some non-default values.
I found some people with a similar problem but their solutions didn't help me.
The solution was to install libjpeg-dev and rebuild (and reinstall) OpenCV.
sudo apt-get install libjpeg-dev

opencv 2.4 really slow compared to pre-built 2.3 on iOS

I'm building openCV with either this script: https://github.com/BloodAxe/OpenCV-iOS-build-script, or this one: https://github.com/aptogo/OpenCVForiPhone.
Compared to their previous already built versions mine is really slow. The only thing I can see different is that in my case opencv is getting compiled with -O0.
Edit: I've tested it with phase correlation and lk and it's 5 times as slow.
Why don't you use cmake as the official documentation suggests?
Edit: make sure you're passing -DCMAKE_BUILD_TYPE=RELEASE to cmake.

Resources