小编use*_*633的帖子

Python OpenCV:无法调整图像大小

我正在使用Python 3和OpenCV 3.我正在尝试使用EigenFace Recognizer,它使用相同大小的图像进行训练和测试数据集.我从网络摄像头读取图像,并将图像调整为200 x 200,但显示错误.

这是我的代码:

faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cam=cv2.VideoCapture(0);
rec=cv2.face.EigenFaceRecognizer_create()
#rec=cv2.face.LBPHFaceRecognizer_create()
rec.read("recognizer/EigenData.xml")
id=0

fontFace = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 1
fontColor = (0, 0, 255)

while(True):
    ret,img=cam.read();

    resize_img = img.resize((200,200) , img)
    gray=cv2.cvtColor(resize_img,cv2.COLOR_BGR2GRAY)
    faces=faceDetect.detectMultiScale(gray,1.3,5);

    for(x,y,w,h) in faces:

        cv2.rectangle(img,(x,y),(x+w, y+h), (0,255,0) , 2)
        id, conf=rec.predict(gray[y:y+h, x:x+w])   #EigenFace Predict
        cv2.putText(img,str(id),(x,y+h), fontFace, fontScale, fontColor,thickness=2)

    cv2.imshow("Face", img);
    if(cv2.waitKey(1)==ord('q')):
        break;

cam.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

resize_img = img.resize((200,200) , img)
TypeError: 'tuple' object cannot be interpreted as an integer
Run Code Online (Sandbox Code Playgroud)

python opencv image image-processing image-resizing

3
推荐指数
1
解决办法
5644
查看次数

Python OpenCV 如何绘制图像的矩形中心并在矩形内裁剪图像?

我使用Python3 OpenCV3。我想绘制图像的矩形中心并在矩形内裁剪图像。我尝试运行此代码,但矩形未显示在图像中心。

width, height, channels = img.shape
cv2.rectangle(img,(0,0),(int(width/2), int(height/2)), (0,255,0) , 2)
Run Code Online (Sandbox Code Playgroud)

如何绘制图像的矩形中心并在矩形内裁剪图像?

python opencv image-processing

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

image-processing ×2

opencv ×2

python ×2

image ×1

image-resizing ×1