I am trying to understand how edge detection works and was trying the code from OpenCV below on Py 2.7, 32 bit:
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('SiliconPost.jpeg',0)
laplacian = cv2.Laplacian(img,cv2.CV)
sobelx = cv2.Sobel(img,cv2.CV,1,0,ksize=5)
sobely = cv2.Sobel(img,cv2.CV,0,1,ksize=5)
plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray')
plt.title('Original'), plt.xticks([]), plt.yticks([])
plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray')
plt.title('Laplacian'), plt.xticks([]), plt.yticks([])
plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray')
plt.title('Sobel X'), plt.xticks([]), plt.yticks([])
plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray')
plt.title('Sobel Y'), plt.xticks([]), plt.yticks([])
plt.show()
But I keep coming across an error:
AttributeError: 'module' object has no attribute 'CV'
How do I go about rectifying this error?
1 Answer 1
From the documentation, ddepth
is the second parameter which defines the depth of the output image and is of type int
.
What you passed to it; cv2.CV
, is nothing. I believe its a typo and you meant to type either cv2.CV_64F
or cv2.CV_16S
or something along these lines.
Refer back to your tutorial to see what was used but you are looking for something along those lines.
Side Note:
CV_16S
, CV_64F
etc are default variables in OpenCV of type int
. You can see this from their implementation.
import cv2
? Is OpenCV properly installed? Try to runhelp(cv2)
to see what happens. Note: post the code you are trying to run in the question, not the link.import cv2
, but I might have messed up the installation. Let me tryhelp(cv2)
.NameError: name 'cv2' is not defined
. Does this mean that OpenCV is not installed correctly?.CV
on a hunch and it worked. It gives another error now:TypeError: an integer is required
.