如何在OpenCV Python中放回裁剪的图像

时间:2019-10-21 05:37:49

标签: python numpy opencv

在这里裁剪图像。

裁剪

    while True:
        # Read the frame and pass it for prediction
        ret, frame = cap.read()
        cv2.namedWindow('image', cv2.WINDOW_NORMAL)
        cv2.resizeWindow('image', 700, 700)
        #cv2.imshow('image', frame)
        frame = cv2.resize(frame, (416, 416))
        og = frame
        if flag != 1:
            r = cv2.selectROI('image', frame)
            print(r)
            roi = frame[int(r[1]):int(r[1]+r[3]), int(r[0]):int(r[0]+r[2])] #cropping
            flag = 1
            cv2.imshow('ROI', roi)
            height, width, channels = roi.shape
        else:
            roi = frame[int(r[1]):int(r[1]+r[3]), int(r[0]):int(r[0]+r[2])]
            height, width, channels = roi.shape
        img = cv2.resize(roi, (416, 416))
        imge = np.array(img).reshape(-1, 416, 416, 3)
        preds = sess.run(model.preds, {inputs: model.preprocess(imge)})

在这里,我想在进行一些分析之后将其粘贴回原始位置

将裁剪后的图像粘贴回

        #Here
        og[int(r[1]):int(r[1]+r[3]), int(r[0]):int(r[0]+r[2])] = tst
        cv2.imshow('image', og)
        if cv2.waitKey(1) & 0xFF == ord('s'):
            flag = 0

0 个答案:

没有答案