Tensorflow 获取原始帧而不是边界框绘制帧
Tensorflow get orginal frame instead of bouding box drawn frame
我正在使用来自 tensorflow github 模型的 object_detection.ipnyb 我修改它以处理视频。现在我想要做的是在 if 条件下获取未修改的框架。 (标记为 << HERE >> )。我尝试将我的框架保存在一个变量 imageOrg 中,但不确定为什么它不起作用。
check=0
count=0
accidents=0
accident=False
prevdate=datetime.datetime.now()
#currdate=datetime.datetime.now()
with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:
while True:
accident=False
ret, image_np = cap.read()
imageOrg=image_np
image_np_expanded = np.expand_dims(image_np, axis=0)
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
scores = detection_graph.get_tensor_by_name('detection_scores:0')
classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
(boxes, scores, classes, num_detections) = sess.run(
[boxes, scores, classes, num_detections],
feed_dict={image_tensor: image_np_expanded})
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8)
for index,value in enumerate(classes[0]):
if scores[0,index] > 0.5:
list1 = [[category_index.get(value)]]
for i in list1:
for j in i:
if j['name'] == 'accident':
accident=True
accidents = accidents + 1
#print(accidents)
if(check == 0 and accidents > 5): << HERE>
<< GET ORIGNIAL NON-MODIFIED FRAME HERE ?? >>
count = count + 1
if(check==1):
accidents=0
if accident==False:
accidents=0
cv2.imshow(videofile[0], cv2.resize(image_np, (600,600)))
if cv2.waitKey(20) & 0xFF == ord('n'):
current = int(cap.get(cv2.CAP_PROP_POS_FRAMES))
print(current)
cap.set(cv2.CAP_PROP_POS_FRAMES,current+50)
if cv2.waitKey(20) & 0xFF == ord('p'):
current = int(cap.get(cv2.CAP_PROP_POS_FRAMES))
print(current)
cap.set(cv2.CAP_PROP_POS_FRAMES,current-50)
if cv2.waitKey(20) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
我使用
修复了它
import crop
imageOrg = copy.copy(image_np)
我正在使用来自 tensorflow github 模型的 object_detection.ipnyb 我修改它以处理视频。现在我想要做的是在 if 条件下获取未修改的框架。 (标记为 << HERE >> )。我尝试将我的框架保存在一个变量 imageOrg 中,但不确定为什么它不起作用。
check=0
count=0
accidents=0
accident=False
prevdate=datetime.datetime.now()
#currdate=datetime.datetime.now()
with detection_graph.as_default():
with tf.Session(graph=detection_graph) as sess:
while True:
accident=False
ret, image_np = cap.read()
imageOrg=image_np
image_np_expanded = np.expand_dims(image_np, axis=0)
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
scores = detection_graph.get_tensor_by_name('detection_scores:0')
classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
(boxes, scores, classes, num_detections) = sess.run(
[boxes, scores, classes, num_detections],
feed_dict={image_tensor: image_np_expanded})
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8)
for index,value in enumerate(classes[0]):
if scores[0,index] > 0.5:
list1 = [[category_index.get(value)]]
for i in list1:
for j in i:
if j['name'] == 'accident':
accident=True
accidents = accidents + 1
#print(accidents)
if(check == 0 and accidents > 5): << HERE>
<< GET ORIGNIAL NON-MODIFIED FRAME HERE ?? >>
count = count + 1
if(check==1):
accidents=0
if accident==False:
accidents=0
cv2.imshow(videofile[0], cv2.resize(image_np, (600,600)))
if cv2.waitKey(20) & 0xFF == ord('n'):
current = int(cap.get(cv2.CAP_PROP_POS_FRAMES))
print(current)
cap.set(cv2.CAP_PROP_POS_FRAMES,current+50)
if cv2.waitKey(20) & 0xFF == ord('p'):
current = int(cap.get(cv2.CAP_PROP_POS_FRAMES))
print(current)
cap.set(cv2.CAP_PROP_POS_FRAMES,current-50)
if cv2.waitKey(20) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
我使用
修复了它import crop
imageOrg = copy.copy(image_np)