gpt4 book ai didi

image - 仅在cv2视频帧的ROI部分上预测模型类

转载 作者:行者123 更新时间:2023-12-02 17:57:58 25 4
gpt4 key购买 nike

以下是我的带有ROI矩形的代码。我只想基于ROI框中捕获的图像而不是整个图像对模型进行预测

import numpy as np
import cv2
from keras.models import load_model
import keras
model = keras.models.load_model('Desktop/BCD_nothing_rmsprop.h5')
def sketch_transform(frame):
return frame

cam_capture = cv2.VideoCapture(0)
cv2.destroyAllWindows()
upper_left = (50, 50)
bottom_right = (300, 300)
while True:
_, image_frame = cam_capture.read()
#Rectangle marker
r = cv2.rectangle(image_frame, upper_left, bottom_right, (100, 50, 200), 5)
rect_img = image_frame[upper_left[1] : bottom_right[1], upper_left[0] : bottom_right[0]]

sketcher_rect = rect_img
sketcher_rect = sketch_transform(sketcher_rect)


#Replacing the sketched image on Region of Interest
image_frame[upper_left[1] : bottom_right[1], upper_left[0] : bottom_right[0]] = sketcher_rect
classes = model.predict(np.array([rect_img]))
cv2.imshow("Sketcher ROI", image_frame)
k = cv2.waitKey(30) & 0xff
if k ==27:
break

cam_capture.release()
cv2.destroyAllWindows()

如何仅预测矩形ROI或变量rect_img内的图像。

最佳答案

之前创建大小调整功能。然后尝试

while True:
_, image_frame = cam_capture.read()
#Rectangle marker
r = cv2.rectangle(image_frame, upper_left, bottom_right, (100, 50, 200), 5)
rect_img = image_frame[upper_left[1] : bottom_right[1], upper_left[0] : bottom_right[0]]

sketcher_rect = rect_img
##Resize ROI first by create function
sketcher_rect = resize_function(sketcher_rect,(width,height))


#Replacing the sketched image on Region of Interest
image_frame[upper_left[1] : bottom_right[1], upper_left[0] : bottom_right[0]] = sketcher_rect
classes = model.predict(sketcher_rect.reshape(1,width,height,3))
cv2.imshow("Sketcher ROI", image_frame)
k = cv2.waitKey(30) & 0xff
if k ==27:
break
cam_capture.release()
cv2.destroyAllWindows()

关于image - 仅在cv2视频帧的ROI部分上预测模型类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64296191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com