Sam Heather
Sam Heather

Reputation: 1503

Why can't I create an image and set it as the background in OpenCV?

So, this is what I am trying:

    import cv2
    import cv2.cv as cv
    cv2.namedWindow(threeDWinName, cv2.CV_WINDOW_AUTOSIZE)
    img2 = cv.CreateImage((320, 240), 32, 1)
    cv2.imshow(threeDWinName,img2)

Does anybody know what is going wrong with this? I get TypeError: <unknown> is not a numpy array

Thanks

Upvotes: 1

Views: 798

Answers (1)

fraxel
fraxel

Reputation: 35269

The more recent version of OpenCV, cv2 uses numpy arrays for images, the preceding version cv used opencv's special Mat's. In your code you've created an image as a Mat using the old cv function CreateImage, and then tried to view it using the newer cv2.imshow function, but cv2.imshow expects a numpy array...

...so all you need to do is import numpy, and then change you CreateImage line to:

img2 = np.zeros((320,240),np.float32)

And then it should be fine :)

Upvotes: 3

Related Questions