Ask Your Question
0

How would I solve this error: TypeError: image is not a numpy array, neither a scalar?

asked 2017-12-31 06:21:20 -0600

updated 2017-12-31 06:39:44 -0600

berak gravatar image

I am following the OpenCV tutorial about image contours and creating the outline of a shape, however on the final line of the code that has been provided I receive the error:

TypeError: image is not a numpy array, neither a scalar

My code reads:

import numpy as np
import cv2

im = cv2.imread("shapes_and_colors.png")
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
im2, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours("shapes_and_colors.png", contours, -1, (0,255,0), 3)

Any help would be greatly appreciated :)

Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-12-31 06:41:37 -0600

berak gravatar image

"shapes_and_colors.png" -- this is a string, a filename, not an image ;)

use this:

cv2.drawContours(im, contours, -1, (0,255,0), 3)
cv2.imshow("shapes_and_colors", im)
cv2.waitKey()
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-12-31 06:21:20 -0600

Seen: 5,507 times

Last updated: Dec 31 '17