window.cpp:366:错误:(-215:断言失败)函数'cv :: imshow'中的size.width> 0 && size.height> 0

时间:2019-06-02 18:54:48

标签: python opencv tensorflow

我使用Tensorflow API进行手部检测,但是当我抽出那只在溺水箱中出现的手时出现此错误

args = parser.parse_args()
print(args.video_source)
cap = cv2.VideoCapture(0)
#cap.set(cv2.CAP_PROP_FRAME_WIDTH, args.width)
#cap.set(cv2.CAP_PROP_FRAME_HEIGHT, args.height)

start_time = datetime.datetime.now()
num_frames = 0
im_width, im_height = (cap.get(3), cap.get(4))
# max number of hands we want to detect/track
num_hands_detect = 2

cv2.namedWindow('Single-Threaded Detection', cv2.WINDOW_NORMAL)

while True:
    # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
    ret, image_np = cap.read()
    image_np = cv2.flip(image_np, 1)
    try:
        image_np = cv2.cvtColor(image_np, cv2.COLOR_BGR2RGB)
    except:
        print("Error converting to RGB")

    # actual detection
    boxes, scores = detector_utils.detect_objects(
        image_np, detection_graph, sess)

    res= detector_utils.get_box_image(
        num_hands_detect, args.score_thresh, scores, boxes, im_width, im_height, image_np)

    # draw bounding boxes
    detector_utils.draw_box_on_image(
        num_hands_detect, args.score_thresh, scores, boxes, im_width, im_height, image_np)

    # Calculate Frames per second (FPS)
    num_frames += 1
    elapsed_time = (datetime.datetime.now() -
                    start_time).total_seconds()
    fps = num_frames / elapsed_time

    if (args.display > 0):
        # Display FPS on frame
        if (args.fps > 0):
            detector_utils.draw_fps_on_image(
                "FPS : " + str(int(fps)), image_np)

        cv2.imshow('Single-Threaded Detection', cv2.cvtColor(
            image_np, cv2.COLOR_RGB2BGR))
        cv2.imshow("b",res)
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break
    else:
        print("frames processed: ",  num_frames,
              "elapsed time: ", elapsed_time, "fps: ", str(int(fps)))

cv2.imshow(“ b”,res)

错误:OpenCV(3.4.6)D:\ Build \ OpenCV \ opencv-

3.4.6 \ modules \ highgui \ src \ window.cpp:366:错误:(-215:声明失败)

函数'cv :: imshow'中

size.width> 0 && size.height> 0

1 个答案:

答案 0 :(得分:0)

OpenCV中的此错误通常意味着由于某种原因,您发送到cv2.imshow的“ res”变量为None,是这种情况吗?