User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

SimpleCV Webcam Trouble.

Sat Jul 18, 2015 2:03 pm

Just messing with SimpleCV edge detection and came across a small problem. The first time I run the script all is good and I get nicely defined edges but on exit the webcam stays on.
Run the script again and I just get a blank (black) window. Run it again and all works well but once more the webcam stays on and I get a blank window the next time and so on, and so on.
I've tried "del cam" and "del disp" as suggested on other forums but nothing works.
Is there a way to tidy everything up on exit ?

Code: Select all

from SimpleCV import *
import time

try:
    cam = Camera()
    disp = Display((640,480))
    
    while not disp.isDone():
        img = cam.getImage()
        edge = img.edges(t1=160)
        edge.show()
        time.sleep(0.04)

except:
    pass
        
Dave.
Apple say... Monkey do !!

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: SimpleCV Webcam Trouble.

Sat Jul 18, 2015 2:28 pm

Update. I've removed the try/except and on closing the window was presented with this error...

Code: Select all

Traceback (most recent call last):
  File "C:\Users\davef_000\Downloads\helloworld.py", line 7, in <module>
    while not disp.isDone():
  File "C:\Python27\lib\site-packages\SimpleCV\Display.py", line 650, in isDone
    self.checkEvents()
  File "C:\Python27\lib\site-packages\SimpleCV\Display.py", line 615, in checkEvents
    pressed = pg.key.get_pressed()
error: video system not initialized
so my original attempt at using "del cam" was never executed.

I now have the following which works

Code: Select all

from SimpleCV import *
import time

try:
    cam = Camera()
    disp = Display((640,480))
    
    while not disp.isDone():
        img = cam.getImage()
        img = img.flipHorizontal()
        edge = img.edges(t1=200)
        edge.show()
        time.sleep(0.04)

except:
    del cam
        
but it isn't a great fix. Any ideas ?

Dave.
Apple say... Monkey do !!

Return to “Python”