python-2.7simplecv

How to turn off the Camera in SimpleCV using python


I am getting the following error when I run the code below:

Error: Camera instance has no attribute 'release'

from SimpleCV import *
import time
def camera(self):
    try:
        cam=Camera(0)
                while cam is not None:
                    try:
                        img = cam.getImage()
                        img.show()
                        time.sleep(0.1)
                    except Exception as e:
                        print(e)
    except Exception as e:
        print(e)
    finally:
        cam.release()
        del cam

Any suggestions how to correct it?


Solution

  • First of all, looking at the documentation/source, it doesn't look like release() is an attribute (i.e. a method) inside the class Camera of SimpleCV, (as the error suggests,) so you're trying to call something that doesn't exist. I would guess that you could omit the line cam.release() since del cam already calls the destructor __del__ which closes the camera for you.

    Please correct me if I'm wrong. Documentation: https://github.com/sightmachine/SimpleCV/blob/master/SimpleCV/Camera.py

    So just:

    finally:
        del cam
    

    PS: I would have just posted a comment but I'm a new user with no rep :)