Ask Your Question
0

TypeError: Required argument 'device' (pos 1) not found

asked 2017-11-02 17:53:38 -0600

salamur gravatar image

updated 2017-11-03 01:07:07 -0600

berak gravatar image

Hello, i am testing a python face-recognition script i found on git. But im currently unable to start capturing with my picamera. Im using this script but keep getting this error:

Traceback (most recent call last):
File "facerecognition.py", line 30, in <module>
camera = config.get_camera(preview)
File "/home/pi/MagicMirror/modules/MMM-Facial-Recognition-Tools/lib/config.py", line 101, in get_camera
return webcam.OpenCVCapture(device_id=0)
File "/home/pi/MagicMirror/modules/MMM-Facial-Recognition-Tools/lib/webcam.py", line 29, in __init__self._camera.open()
TypeError: Required argument 'device' (pos 1) not found

As i said im using a picam, opencv and python 2.7. Isn't __init__self._camera.open() going conform with opencv 3.3?

Thanks, best regards.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2017-11-03 01:05:16 -0600

berak gravatar image

updated 2017-11-03 01:40:53 -0600

there is no such thing as cv2.VideoCapture.open() (without any arguments)

that's just bad code, a bug, if you want. problem is here

    self._camera = cv2.VideoCapture(device_id)
    if not self._camera.isOpened():
        self._camera.open()

see, problem is, what to do, if the camera could not be opened with the specified id ? the author did not have a case for that, it probably did never happen to him, but again, bad code ...

proposal: raise an exception, and stop it:

    self._camera = cv2.VideoCapture(device_id)
    if not self._camera.isOpened():
        raise Exception("could not open camera " + str(device_id))

(then, btw, opencv's face-recognition is made for identification (closest from a database), while the task there seems to be authentification (is that me?) -- it's the wrong tool for the job)

(be suspicious of anything in that codebase !)

edit flag offensive delete link more

Comments

But im currently having an argument --> device_id is set to 0 and in the opencv docs you can find: device – id of the opened video capturing device (i.e. a camera index). If there is a single camera connected, just pass 0 and the picam is the only cam which is connected

I added an expection to stop it. It throws obviously "could not open camera".

Yeah, it's just a part of this recognition-module

salamur gravatar imagesalamur ( 2017-11-03 02:58:13 -0600 )edit

that is sad, but it means, there is a configuration problem (not your code).

check cv2.getBuildInformation(), maybe the Video IO section has something useful (i.e no support for V4L/V4L2 built in)

berak gravatar imageberak ( 2017-11-03 03:06:16 -0600 )edit

https://pastebin.com/excxAhYB I checked the build information. V4L/V4L2 should be fine. Maybe you could check it too?

salamur gravatar imagesalamur ( 2017-11-03 12:34:25 -0600 )edit

no, i'll just believe you ;)

still, at this point, you have to worry about drivers, os, hardware and such, it's no more a "what's wrong with my python code" problem (and i cannot help you any more)

berak gravatar imageberak ( 2017-11-03 12:41:00 -0600 )edit

I have no issues problem with picamera. I'm using RPI 3, OpenCV 3.3.1 and python 3.5. There is minor changed from OpenCV too.

supra56 gravatar imagesupra56 ( 2017-11-04 08:15:51 -0600 )edit

In OpenCV 3.3.1. in face.py ...... change this import config to import lib.config as config

supra56 gravatar imagesupra56 ( 2017-11-04 08:24:32 -0600 )edit

I do already.

salamur gravatar imagesalamur ( 2017-11-04 08:32:04 -0600 )edit

@salamur. Does your picamera working?

supra56 gravatar imagesupra56 ( 2017-11-04 09:16:43 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-11-02 17:53:38 -0600

Seen: 10,671 times

Last updated: Nov 03 '17