调整图像大小时出错

时间:2017-08-09 17:48:53

标签: python opencv

我使用以下代码裁剪面部并保存。

 while True:
        # Capture frame-by-frame
        ret, frame = video_capture.read()

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        faces = faceCascade.detectMultiScale(
            gray,
            scaleFactor=1.1,
            minNeighbors=5,
            minSize=(30, 30),
            flags=cv2.CASCADE_SCALE_IMAGE
        )

        # Draw a rectangle around the faces
        for (x, y, w, h) in faces:
            cv2.rectangle(frame, (x - 60, y - 60), (x + w, y + h), (0, 255, 0), 2)
            imgCrop = frame[y - 60:y + h, x - 60:x + w]

            imgCrop = cv2.resize(imgCrop, (224, 224), interpolation=cv2.INTER_CUBIC)

            cv2.imwrite("check.jpg", imgCrop)

我这样做时出现以下错误。

  

imgCrop = cv2.resize(imgCrop,(224,224),   interpolation = cv2.INTER_CUBIC)cv2.error:   /Users/jenkins/miniconda/1/x64/conda-bld/conda_1486587097465/work/opencv-3.1.0/modules/imgproc/src/imgwarp.cpp:3229:错误:(-215)ssize.area()> 0在函数调整大小

我怎样才能解决这个问题?

更新

 if ret:
        # Draw a rectangle around the faces
        for (x, y, w, h) in faces:

            cv2.rectangle(frame, (x - 60, y - 60), (x + w, y + h), (0, 255, 0), 2)
            imgCrop = frame[y - 60:y + h, x - 60:x + w]

            imgCrop = cv2.resize(imgCrop, (224, 224), interpolation=cv2.INTER_CUBIC)

            cv2.imwrite("check.jpg", imgCrop)

0 个答案:

没有答案