I'm trying to convert images taken from a capture (webcam) and do some processing with them using OpenCV, but I have a hard time.
When you try to convert an image to grayscale, the program crashes. (Python.exe stops working)
Here is the main snippet of my code:
newFrameImageGS = cv.CreateImage ((320, 240), cv.IPL_DEPTH_8U, 1)
for i in range(0,5):
newFrameImage = cv.QueryFrame(ps3eye)
cv.CvtColor(newFrameImage,newFrameImageGS,cv.CV_BGR2GRAY)
golfSwing.append(newFrameImageGS)
When I try to use cvConvertScale, I get an assertion error:
src.size() == dst.size() && src.channels() == dst.channels()
which makes sense, but I'm pretty confused about how to go about converting my webcam input images into images that can be used by functions like cvUpdateMotionHistory () and cvCalcOpticalFlowLK ()
Any ideas? Thanks.
UPDATE:
I converted the image to grayscale manually using this:
for row in range(0,newFrameImage.height):
for col in range(0,newFrameImage.width):
newFrameImageGS[row,col] = (newFrameImage8U[row,col][0] * 0.114 + # B
newFrameImage8U[row,col][1] * 0.587 + # G
newFrameImage8U[row,col][2] * 0.299) # R
. , cvCvtColor .