SaikiHanee
SaikiHanee

Reputation: 881

AttributeError: 'module' object has no attribute 'cv'

I am getting the following error while trying to do a BGR to binary threshhold conversion.

imgthreshhold = cv2.inRange(img, cv2.cv.Scalar(3,3,125), cv2.cv.Scalar(40,40,255)) AttributeError: 'module' object has no attribute 'cv'

Following is the complete program.

import cv2

cap = cv2.VideoCapture(0)
#help(cv2)
while cap.isOpened():
    #BGR image feed from camera
    ret, img = cap.read()
    cv2.imshow('output', img)
    #BGR to grayscale
    img2 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    cv2.imshow('grayscale', img2)
    #BGR to binary(RED) thershholded
    imgthreshhold = cv2.inRange(img, cv2.cv.Scalar(3,3,125), cv2.cv.Scalar(40,40,255))
    cv2.imshow('threshholded', imgthreshhold)

    k = cv2.waitKey(10)
    if k==27:
        break

cap.release()
cv2.destroyAllWindows()

How can I fix this?

Upvotes: 0

Views: 11297

Answers (1)

thegravity
thegravity

Reputation: 100

I had been facing the same issue. And I think we are following the same tutorial for OpenCV. I messed around with the function a little, and found that only providing the values worked fine.

So this is how your code should look like:

import cv2

cap = cv2.VideoCapture(0)
#help(cv2)
while cap.isOpened():
    #BGR image feed from camera
    ret, img = cap.read()
    cv2.imshow('output', img)
    #BGR to grayscale
    img2 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    cv2.imshow('grayscale', img2)
    #BGR to binary(RED) thershholded
    imgthreshhold = cv2.inRange(img, (3,3,125), (40,40,255))
    cv2.imshow('threshholded', imgthreshhold)

    k = cv2.waitKey(10)
    if k==27:
        break

cap.release()
cv2.destroyAllWindows()

Upvotes: 1

Related Questions