2

I'm trying to use SimpleCV for image capture in Python (Windows). Capture is performed inside a function, which I want to run inside a thread. This is my code:

# -*- encoding: utf-8 -*-

import threading
import time
from SimpleCV import Camera

def run(filename):
    # Initialize the camera
    cam = Camera(0, {"width": 640, "height": 480})
    while 1:
        img = cam.getImage()
        img.save(filename, quality=50, optimize=True, progressive=True)
        time.sleep(3)


filename = "C:/SimpleCV/image.jpeg"

t = threading.Thread(target=run, args=(filename,))
t.start()

while(1):
    time.sleep(1) 

If I call the run() function directly (with no threads) everything's ok. However, when using a thread (as in the above code), Windows shows a dialog asking for the capture source and program crashes. What's the problem?

Error codes:

OpenCV Error: Bad argument (Array should be CvMat or IplImage) in unknown function, file C:\slave\WinInstallerMegaPack\src\opencv\modules\core\src\array.cpp, line 1238
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 551, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 504, in run
    self.__target(*self.__args, **self.__kwargs)
  File "C:/SimpleCV/test.py", line 12, in run
    img = cam.getImage()
  File "C:\Python27\lib\site-packages\SimpleCV\Camera.py", line 586, in getImage
    newimg = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_8U, 3)
error: Array should be CvMat or IplImage 
Rafael
  • 7,002
  • 5
  • 43
  • 52
sysseon
  • 177
  • 3
  • 14

0 Answers0