1

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?

asked Jun 27, 2017 at 17:09
11
  • Did you import cv2? Is OpenCV properly installed? Try to run help(cv2) to see what happens. Note: post the code you are trying to run in the question, not the link. Commented Jun 27, 2017 at 17:27
  • Yes, I did import cv2, but I might have messed up the installation. Let me try help(cv2). Commented Jun 27, 2017 at 18:43
  • @KelvinS, I shall post the code right away. Thank you! Commented Jun 27, 2017 at 18:43
  • @KelvinS I am getting the error NameError: name 'cv2' is not defined. Does this mean that OpenCV is not installed correctly? Commented Jun 27, 2017 at 18:47
  • @KelvinS, actually, I took out .CV on a hunch and it worked. It gives another error now: TypeError: an integer is required. Commented Jun 27, 2017 at 18:51

1 Answer 1

2

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.

answered Jun 27, 2017 at 19:56

1 Comment

It did for sure! Thank you!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.