africanwizz
Posts: 1
Joined: Fri Jan 23, 2015 12:33 pm

picamera with opencv

Thu Jan 29, 2015 6:31 pm

Hi, i just recently got myself a raspberry pi b+ (wooohoooo!!) along with the camera module. I attempt to use the picamera alongside open CV in the code using modified examples form the openCV and picamera sites.
However , when i run this , a blank frame is displayed, i initally this with only the BGR2GRAY and it worked fine, as soon as i added all the code to do colour detection , it just displays a blank frame,what am i doing wrong here???. i am also very new to python .
Thanks in advance

Code: Select all

import io
import time
import picamera
import picamera.array
import numpy as np
import cv2

with picamera.PiCamera() as camera:
        camera.vflip = True
        camera.brightness = 65
        camera.ISO = 800
        time.sleep(2)
        while(True):
                with picamera.array.PiRGBArray(camera) as stream:
                        camera.capture(stream, format='bgr')
                        image = stream.array
                a=time.time()
                hsv = cv2.cvtColor(image,cv2.COLOR_BGR2HSV)

                lower_limit = np.array([110,50,50])
                upper_limit = np.array([130,255,255])

                mask = cv2.inRange(hsv,lower_limit,upper_limit)
   
                res = cv2.bitwise_and(image,image,mask = mask)
                b=time.time()
                ans = b-a
                print ans
                time.sleep(2)
                #cv2.imshow('frame',image)
                #cv2.imshow('mask',mask)
                cv2.imshow('frame',res)

               

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


pjuangph
Posts: 1
Joined: Mon Jul 15, 2019 4:17 am

Re: picamera with opencv

Mon Jul 15, 2019 4:20 am

I had the same issue.
I included this line of code before the loop
cv2.startWindowThread()

Return to “Python”