BakaUPSB
BakaUPSB

Reputation: 11

Opencv installed however python does not find the package

I have recently installed opencv on my raspberry pi 3 module B to do some vision processing and whilst I was developing this code for said processing I ran my code which is

 import cv2
 import numpy as np
 vid = cv2.VideoCapture(0)
 vid.set(10,.05)

def onmouse(k,x,y,s,p):
   global hsv
   if k==1:   # left mouse, print pixel at x,y
      print hsv[y,x]

while(True):
cv2.namedWindow("hsv")
cv2.setMouseCallback("hsv",onmouse);
cv2.imshow('hsv',hsv)
ret, frame = vid.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_green = np.array([75,200,200])
upper_green = np.array([85,255,255])
mask = cv2.inRange(hsv, lower_green, upper_green)
res = cv2.bitwise_and(frame,frame,mask=mask)
cv2.imshow('orig',frame)
cv2.imshow('fff',res)

if cv2.waitKey(1) & 0xFF == ord('q'):
    break


vid.release()
cv2.destroyAllWindows()

after finishing this I ran my code to see if no errors occurred however I was presented by this

I was wondering if either I did something wrong with my code or I screwed up in installing opencv. Either way I would be grateful if anyone either had experiences with this same problem or someone has already resolved this issue.

FYI: I got the instructions to install opencv from this site

As well as sorry for my messy code never really got the the hang of having everything neat as well as my potentially dumb question either way; Thank you for your attention

Upvotes: 1

Views: 232

Answers (1)

emnoor
emnoor

Reputation: 2708

It appears the name of your script is cv2.py. So when you import cv2, it imports this script instead of the cv2 library. Use a different script name.

Upvotes: 1

Related Questions