Disclaimer: huge openCV noob
Traceback (most recent call last):
File \"lanes2.py\", line 22, in
canny = canny(lane_image)
Is canny
your own function? Do you use Canny from OpenCV inside it? If yes check if you feed suitable argument for Canny
- first Canny
argument should meet following criteria:
<type 'numpy.ndarray'>
dtype('uint8')
shape
should be 2-tuple
of int
s (tuple
containing exactly 2 integers)You can check it by printing respectively
type(variable_name)
variable_name.dtype
variable_name.shape
Replace variable_name
with name of variable you feed as first argument to Canny
.
I got round thid by writing/reading to a file. I guessed cv.imread would put it into the format it needed. This code for anki Vector SDK program but you get the idea.
tmpImage = robot.camera.latest_image.raw_image.save('temp.png')
pilImage = cv.imread('temp.png')
src
is the first argument to cv2.cvtColor
.
The error you are getting is because it is not the right form. cv2.Umat()
is functionally equivalent to np.float32()
, so your last line of code should read:
gray = cv2.cvtColor(np.float32(imgUMat), cv2.COLOR_RGB2GRAY)
Just add this at start: image = cv2.imread(image)
Not your code is the problem this is perfectly fine:
gray = cv2.cvtColor(imgUMat, cv2.COLOR_RGB2GRAY)
The problem is that imgUMat is None
so you probably made a mistake when loading your image:
imgUMat = cv2.imread("your_image.jpg")
I suspect you just entered the wrong image path.
Sometimes I have this error when videostream from imutils package doesn't recognize frame or give an empty frame. In that case, solution will be figuring out why you have such a bad frame or use a standard VideoCapture(0) method from opencv2