【发布时间】:2020-06-05 01:43:03
【问题描述】:
我可以通过将帧作为图像然后处理来处理视频帧。但无法直接传帧到物体检测。 使用 imwrite 保存图像会使程序变慢...
这是我的主要方法:
cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=2), cv2.CAP_GSTREAMER)
if cap.isOpened():
window_handle = cv2.namedWindow("CSI Camera", cv2.WINDOW_AUTOSIZE)
# Window
while cv2.getWindowProperty("CSI Camera", 0) >= 0:
ret_val, frame = cap.read()
if not ret_val:
break
frame = imutils.resize(frame, width=600)
#cv2.imwrite('box.jpg', frame)
#image = Image.open(path)
#Error in here!!!
predictions = od_model.predict_image(frame)
for x in range(len(predictions)):
probab = (predictions[x]['probability'])*100
if(probab > 45):
print(predictions[x]['tagName'], end=' ')
print(probab)
#cv2.imshow("CSI Camera", frame)
# This also acts as
keyCode = cv2.waitKey(30) & 0xFF
# Stop the program on the ESC key
if keyCode == 27:
break
cap.release()
cv2.destroyAllWindows()
else:
print("Unable to open camera")
错误信息:
predictions = od_model.predict_image(frame)
File "/home/bharat/New_IT3/object_detection.py", line 125, in
predict_image
inputs = self.preprocess(image)
File "/home/bharat/New_IT3/object_detection.py", line 130, in
preprocess
image = image.convert("RGB") if image.mode != "RGB" else image
AttributeError: 'numpy.ndarray' object has no attribute 'mode'
【问题讨论】:
-
如果你取消注释#cv2.imwrite('box.jpg', frame) #image = Image.open(path) then??
-
然后它正在工作,但一次又一次地将图像写入内存会减慢进程。我正在寻找直接传递对象
-
from PIL import Image im = Image.fromarray(frame) //导入PIL包
标签: opencv tensorflow object-detection nvidia-jetson-nano