Ask Your Question
0

Error CreateImage()

asked 2014-04-19 17:32:20 -0600

jkz gravatar image

updated 2014-04-20 03:42:38 -0600

berak gravatar image

Hi there! I'm getting this error

imageResized=cv.CreateImage((64,64),8, 1)
NameError: name 'cv' is not defined

Here is my code:
import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
    retval, frame = cap.read()
    cv2.imshow("frame",frame)
    cv2.waitKey(10)
    a = (200,80)#(x,y)
    b = (450,400)#(x,y)
    cv2.rectangle(frame,a, b, (0,255,0),3)
    crop_frame=frame[80:400,200:450] #y,x

    cv2.imwrite("face.jpg", frame)

    frame=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)   
    imageResized=cv.CreateImage((64,64),8, 1)
    cv.Resize(cv.fromarray(frame), imageResized)
    vector = numpy.asarray(frame)
    print vector

I've changed to cv2.CreateImage and get this: "AttributeError: 'module' object has no attribute 'CreateImage'" Can you guys help me? thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-04-20 03:41:20 -0600

berak gravatar image

you should stick with the cv2 api, which does not use CreateImage any more.

(cv.CreateImage is from the old c-api based python wrapper, try not to use any of the cv. functions)

in cv2, all images are numpy arrays, so you can use either cv2 or numpy functions to process them.

>>> import cv2
>>> help(cv2.resize)
Help on built-in function resize in module cv2:

resize(...)
    resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) -> dst

>>> import numpy as np
>>> help(np.resize)
Help on function resize in module numpy.core.fromnumeric:

resize(a, new_shape)
    Return a new array with the specified shape.
...

so, if you use cv2.resize(), it returns a new array, while numpy.resize() works inplace.

none of them require creating a new image, (that's one of the main differences to the old cv api).

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-04-19 17:32:20 -0600

Seen: 8,765 times

Last updated: Apr 20 '14