opencv 3.0.0-dev python bindings not working properly - python

I am on ubuntu 14.04.02, i have python, cython and numpy installed and updated.
i pulled the latest sources of open cv from http://github.com/itseez/opencv, compiled according to the documentation...
when trying to run the python source i pulled from https://github.com/shantnu/FaceDetect/
it's giving me the following error :
modprobe: FATAL: Module nvidia not found.
Traceback (most recent call last):
File "face_detect.py", line 21, in
flags = cv2.cv.CV_HAAR_SCALE_IMAGE
AttributeError: 'module' object has no attribute 'cv'
to make sure i have the python bindings i typed the following in the terminal:
python
import cv2
cv2.__version__
it returned the following
'3.0.0-dev'
what could be wrong with it?

the cv2.cv submodule got removed in opencv3.0, also some constants were changed.
please use cv2.CASCADE_SCALE_IMAGE instead
(do a help(cv2) to see the updated constants)

Apologies for the bump, but the above did not work for me, and I found an alternate "solution", but it may have unwanted side effects, given I know SFA about openCV.
The simple solution is just set it to 0.
# Detect faces in the image
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
# flags = cv2.cv.CV_HAAR_SCALE_IMAGE
flags = 0
)
As you can see... i just set it to 0 and could move on with my life.
I tried all number of combinations, and I couldn't get the CASCADE_SCALE_IMAGE working.
This openCV doco explaination gives me nadda, zip, nothing but confusion.
flags – Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.
That cleared it up...
Anyway, the example on openCV hard codes it to 0.

Related

Python 3-ValueError: not enough values to unpack (expected 3, got 2)

Hi I am a new to computer visionand stackoverflow and I have a problem with my python 3 program on Windows,as the cv2.findContours() function returns 2 instead of three values as in the documentation. I passed 2 values for return to solve the bug,the type of the first(image) is a list and that of the second (cnts)is an int32 but none of them is abled to be used in cv2.drawContours() without bugging here I use image as parameter in because it is the only list returned so I guess it is the contours list cv2.drawContours().So here is the code:
#This is the program for a document scanner so as to extract a document
#from any image and apply perspective transform to show it as final result
import numpy as np
import cv2
import imutils
from matplotlib import pyplot as plt
cap=cv2.VideoCapture(0)
ret,img=cap.read()
img1=img.copy()
cv2.imshow('Image',img1)
img1=cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
img1=cv2.bilateralFilter(img1,7,17,17)
img1=cv2.Canny(img1,30,200)
image,cnts=cv2.findContours(img1,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
#cnts=np.asarray(cnts,dtype='uint8')
cnts=np.array(cnts)
cv2.imshow('Edge',img1)
print('cnts var data type',cnts.dtype)
#print("Hi")
img=cv2.drawContours(img,[image],-1,(255,255,0),3)
Here is the python idle shell result appearing now:
cnts var data type is int32
Traceback (most recent call last):
File "D:\PyCharm Projects\Test_1_docscanner.py", line 20, in <module>
img=cv2.drawContours(img,[image],-1,(255,255,0),3)
TypeError: contours is not a numpy array, neither a scalar
I got it working finally,the following I did:
First I had previously messed up with most of my environmental variables haven suppressed some system variables. So I with help of a friend I retrieved as much as I could and deleted those I had stupidly ignorantly created.
Secondly I uninstalled all other python versions(at least I tried) though it seems that I still see their icons around(they seem to be "undeletable") and even the one I was using(Python3.7.3). I then install Python 3.7.4.
Thirdly,and that must be the answer is that I added this line cnts=imutils.grab_contours(cnts) before the cv2.drawContours() functions. Getting this from imutils package from Adrian Rosebrock github. my code now works because of that line which helps to parse the contours for whatever cv2.drawContours() opencv version you are using thereby avoiding conflicts of versions originating from cv2.findContours() function used prior to cv2.drawContours().
In conclusion I tried imutils.grab_contours() previously to these changes on my python3.7.3 but it did not work. But I believe above all the combination of "cnts=imutils.grab_contours(cnts)" and the update to Python3.7.4,is what solved the issue.
Hope this is helpful

Error with obtaining license OpenCV project

I am trying to make a machine learning model with Python. However, I keep getting this error:
LSD = cv2.createLineSegmentDetector(_refine=cv2.LSD_REFINE_ADV, _quant=qError)
cv2.error: OpenCV(4.2.0) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/lsd.cpp:143: error: (-213:The function/feature is not implemented) Implementation has been removed due original code license issues in function 'LineSegmentDetectorImpl'
My code is as follows:
_, vp, _, _, panoEdge, _, _ = panoEdgeDetection(img_ori,
qError=args.q_error,
refineIter=args.refine_iter)
panoEdge = (panoEdge > 0)
How can I fix this? Thanks to all. Satya
This seems to be happening due to the function LineSegmentDetectorImpl being deprecated in latest version. For example, if you are using this opencv-contrib-python==4.1.1.26 and opencv-python==4.1.1.26.
To solve it:
Downgrade to opencv-contrib-python==4.0.0.21 and opencv-python==4.0.0.21.
According to this question on Stakoverflow, to replace the missing LineSegmentDetectorImpl, install pylsd using pip install pylsd. For more details about how to use it with opencv, please check the documentation.
This should solve the problem.

OpenCV Error: Bad argument in ERClassifierNM1

I run opencv 3.2.0, ubuntu 14.04, and latest opencv_contrib.
I run examine:
https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/textdetection.py
But it have show err:
$ python textdetection.py scenetext_word01.jpg
textdetection.py
A demo script of the Extremal Region Filter algorithm described in:
Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, CVPR 2012
Extracting Class Specific Extremal Regions from 9 channels ...
(...) this may take a while (...)
OpenCV Error: Bad argument (Default classifier file not found!) in ERClassifierNM1, file /home/vietnam/opencv_and_contri/opencv_contrib/modules/text/src/erfilter.cpp, line 1022
Traceback (most recent call last):
File "textdetection.py", line 38, in <module>
erc1 = cv2.text.loadClassifierNM1(pathname+'/trained_classifierNM1.xml')
cv2.error: /home/vietnam/opencv_and_contri/opencv_contrib/modules/text/src/erfilter.cpp:1022: error: (-5) Default classifier file not found! in function ERClassifierNM1
How to solve this?
Try using relative paths in the parameters for cv2.text.loadClassifierNM1() and cv2.text.loadClassifierNM2()
So now that part of the code looks like this:
erc1 = cv2.text.loadClassifierNM1('./trained_classifierNM1.xml')
er1 = cv2.text.createERFilterNM1(erc1,16,0.00015,0.13,0.2,True,0.1)
erc2 = cv2.text.loadClassifierNM2('./trained_classifierNM2.xml')
er2 = cv2.text.createERFilterNM2(erc2,0.5)
I'm not sure why this works (it did for me), but I tried this after looking at a solution posted for a similar problem in VS2015 here: https://github.com/cesardelgadof/OpenCVBinaries/issues/1
Hope this helps.
Trying with absolute path e.g. "/usr/lib/opencv-3.2.0/opencv_contrib-3.2.0/modules/text/samples/trained_classifierNM1.xml" worked in my case for Ubuntu 16.04, C++

Error when using OpenCV face detection

I am try to get face detection working on using a python script and OpenCV but I keep getting this error:
Traceback (most recent call last)
File "face_detect.py", line 19, in <module>
cascade = cv.Load(options, cascade)
TypeError: OpenCV returned NULL
The code I used is here: https://github.com/mitchtech/py_servo_facetracker
I don know what is causing this error or how to fix it. Thanks in advance.
if you put on your goggles ;)
you'll see, that it's not
cascade = cv.Load(options, cascade)
in the original code, but :
cascade = cv.Load(options.cascade)
( and a remark: the old cv api got removed in newer opencv versions, you probably should avoid it in favour of cv2 )
I had the same issue. For me, the relative-path of the haarcascade was incorrect. It thought the data folder was one level up, instead it was two.
My changes
Original:
parser.add_option("-c", "--cascade", action="store", dest="cascade", type="str", help="Haar cascade file, default %default", default = "../data/haarcascades/haarcascade_frontalface_alt.xml")
Modified:
parser.add_option("-c", "--cascade", action="store", dest="cascade", type="str", help="Haar cascade file, default %default", default = "../../data/haarcascades/haarcascade_frontalface_alt.xml")
I met the same issue, and it seems like the file path of haarcascade_frontalface_alt.xml is not correct.
You should download haarcascade_frontalface_alt.xml to your computer from http://eclecti.cc/files/2008/03/haarcascade_frontalface_alt.xml.
So I fixed it by changing the file path of haarcascade_frontalface_alt.xml. Hope it will help!

opencv getImage() error

I wrapped opencv today with simplecv python interface. After going through the official SimpleCV Cookbook I was able to successfully Load, Save, and Manipulate images. Thus, I know the library is being loaded properly.
However, under the Using a Camera, Kinect, or Virtual Camera heading I was unsuccessful in running some commands. In particular, mycam = Camera() worked, but img = mycam.getImage() produced the following error:
In [35]: img = mycam.getImage().save()
OpenCV Error: Bad argument (Array should be CvMat or IplImage) in cvGetSize, file /home/jordan/OpenCV-2.2.0/modules/core/src/array.cpp, line 1237
---------------------------------------------------------------------------
error Traceback (most recent call last)
/home/simplecv/<ipython console> in <module>()
/usr/local/lib/python2.7/dist-packages/SimpleCV-1.1-py2.7.egg/SimpleCV/Camera.pyc in getImage(self)
332
333 frame = cv.RetrieveFrame(self.capture)
--> 334 newimg = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_8U, 3)
335 cv.Copy(frame, newimg)
336 return Image(newimg, self)
error: Array should be CvMat or IplImage
I'm running Ubuntu Natty on a HP TX2500 tablet. It has a built in webcam, (CyberLink Youcam?) Has anybody seen this error before? I've been all over the web today looking for a solution, but nothing seems to be doing the trick.
Update 1: I tested cv.QueryFrame(capture) using the code found here in a separate Stack Overflow question and it worked; so I've pretty much nailed this down to a webcam issue.
Update 2: In fact, I get the exact same errors on a machine that doesn't even have a webcam! It's looking like the TX2500 is not compatible...
since the error raised from Camera.py of SimpleCV, you need to debug the getImage() method. If you can edit it:
def getImage(self):
if (not self.threaded):
cv.GrabFrame(self.capture)
frame = cv.RetrieveFrame(self.capture)
import pdb # <-- add this line
pdb.set_trace() # <-- add this line
newimg = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_8U, 3)
cv.Copy(frame, newimg)
return Image(newimg, self)
then run your program, it will be paused as pdb.set_trace(), here you can inspect the type of frame, and try to figure out how get the size of frame.
Or you can do the capture in your code, and inspect the frame object:
mycam = Camera()
cv.GrabFrame(mycam.capture)
frame = cv.RetrieveFrame(mycam.capture)
To answer my own question...
I bought a Logitech C210 today and the problem disappeared.
I'm now getting warnings:
Corrupt JPEG data: X extraneous bytes before marker 0xYY.
However, I am able to successfully push a video stream to my web-browser via JpegStreamer(). If I cannot solve this error, I'll open a new thread.
Thus, for now, I'll blame the TX2500.
If anybody finds a fix in the future, please post.
Props to #HYRY for the investigation. Thanks.
I'm geting the camera with OpenCV
from opencv import cv
from opencv import highgui
from opencv import adaptors
def get_image()
cam = highgui.cvCreateCameraCapture(0)
im = highgui.cvQueryFrame(cam)
# Add the line below if you need it (Ubuntu 8.04+)
#im = opencv.cvGetMat(im)
return im
Anthony, one of the SimpleCV developers here.
Also instead of using image.save(), this function writes the file/video to disk, you instead probably want to use image.show(). You can save if you want, but you need to specify a file path like image.save("/tmp/blah.png")
So you want to do:
img = mycam.getImage()
img.show()
As for that model of camera I'm not sure if it works or not. I should note that we also wrapper different camera classes not just OpenCV, this is because OpenCV has a problem with webcams over 640x480, we now can do high resolution cameras.
Also I should mention, which I didn't realize, is that OpenCV less than 2.3 is broken with webcams on Ubuntu 11.04 and up. I didn't realize this as I was running Ubuntu 10.10 before, by the looks of your output you are using python 2.7 which makes me think you are on Ubuntu 11.04 or higher. Anyway, we have a fix for this problem. It is now pushed up into the master, it basically does a check to see if OpenCV is working, if not it will fall back to pygame.
This fix will also be in the 1.2 release of SimpleCV (It's in the master branch now)

Categories

Resources