Ask Your Question
0

TypeError: Expected cv::UMat for argument 'img'

asked 2019-07-25 03:26:41 -0600

yuki gravatar image

I converted image into numpy array. <class 'numpy.ndarray'=""> But still why I am facing this error.

accum_time = 0
    curr_fps = 0
    fps = "FPS: ??"
    prev_time = timer()

while True:
        return_value, frame = vid.read()
        image = Image.fromarray(frame)
        image = detect_image(image)
        result = np.asarray(image)
        curr_time = timer()
        exec_time = curr_time - prev_time
        prev_time = curr_time
        accum_time = accum_time + exec_time
        curr_fps = curr_fps + 1
        if accum_time > 1:
            accum_time = accum_time - 1
            fps = "FPS: " + str(curr_fps)
            curr_fps = 0

        cv2.putText(result, text=fps, org=(3, 15), fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                    fontScale=0.50, color=(255, 0, 0), thickness=2)

        cv2.namedWindow("result", cv2.WINDOW_NORMAL)
        cv2.imshow("result", result)


Traceback (most recent call last):
File "detect.py", line 228, in detect_ob
 fontScale=0.50, color=(255, 0, 0), thickness=2)
TypeError: Expected cv::UMat for argument 'img'
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-03-10 23:17:14 -0600

frankcarey gravatar image

Your image returned from detect_image() is probably not contiguous. You can check with

assert image.flags['C_CONTIGUOUS'] == True

and if it that fails, you can make it contiguous with

image = np.ascontiguousarray(image)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-07-25 03:26:41 -0600

Seen: 10,092 times

Last updated: Mar 10 '20