Ask Your Question
0

opencv 4.1.2 - TypeError: Expected Ptr<cv::UMat> for argument '%s'

asked 2019-12-25 16:49:16 -0600

isjosan gravatar image

updated 2019-12-26 02:08:29 -0600

berak gravatar image

I have opencv 4.1.2 installed on pi3B+ with a picamera connected and I am trying to use cv2 to find contours in delta image frame; here's the traceback that I get if cv2.contourArea(c) < conf["min_area"]: TypeError: Expected Ptr<cv::umat> for argument '%s'

Here's the code snippet that throws the above Traceback:

#threshold delta image, dilate threshold image to fill in holes, then find contours on threshold image
    thresh = cv2.threshold(frameDelta, conf["delta_thresh"], 255, cv2.THRESH_BINARY)[1]
    thresh = cv2.dilate(thresh, None, iterations=2)
    cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

# loop over contours
for c in cnts:
    #if contour is too small, ignore it
    **if cv2.contourArea(c) < conf["min_area"]:**
          continue

    # compute bounding box for contour, draw it on the frame and update text
    (x, y, w, h) = cv2.boundingRect(c)
    cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
    text = "Occupied"

Is it a bug in cv 4.1.2? I noticed a similar bug was fixed in version 3.4 (#15834). If yes, will the fix be merged in opencv 4.1.2?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
2

answered 2019-12-27 10:30:37 -0600

isjosan gravatar image

I fixed my code to use tuple returned by findContours(); that has fixed my issue with motion detection code in OpenCv 4.1.2.

Thanks a lot !

edit flag offensive delete link more
1

answered 2019-12-26 02:23:25 -0600

berak gravatar image

no, not a bug, error on your side.

cv2.findcontours() returns a (contours, hierarchy) tuple, not contours only

edit flag offensive delete link more

Comments

This helped to solve my issue, Thanks!

Scott_777 gravatar imageScott_777 ( 2020-12-08 21:22:05 -0600 )edit
0

answered 2020-01-14 23:45:29 -0600

to fixed my code to use tuple lower back through findContours(); that has fixed my problem with movement detection code in OpenCv 4.1.2.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-12-25 16:49:16 -0600

Seen: 11,084 times

Last updated: Jan 14 '20