我试图用覆盆子pi制作一台照相机,该照相机可以计算并发送火柴盒中人员的数量。
我遵循了https://github.com/EdjeElectronics/TensorFlow-Object-Detection-on-the-Raspberry-Pi的教程 但是我不能仅将检测限制为该人,也不可以计算要在房间中检测的人数。我可以发送到Firebase,但人数不正确。
我在stackeoverflow上尝试了几个答案,但是它不能作为How to count objects in Tensorflow Object Detection API工作 因为他们不存在只计算人数的问题。
我如何只统计房间中的人数? 这是我的代码:
for frame1 in camera.capture_continuous(rawCapture, format="bgr",use_video_port=True):
totalcount=0
t1 = cv2.getTickCount()
# Acquire frame and expand frame dimensions to have shape: [1, None, None, 3]
# i.e. a single-column array, where each item in the column has the pixel RGB value
frame = np.copy(frame1.array)
frame.setflags(write=1)
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame_expanded = np.expand_dims(frame_rgb, axis=0)
# Perform the actual detection by running the model with the image as input
(boxes, scores, classes, num) = sess.run(
[detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: frame_expanded})
boxes = np.squeeze(boxes)
scores = np.squeeze(scores)
classes = np.squeeze(classes)
indices = np.argwhere(classes == 1)
boxes = np.squeeze(boxes[indices])
scores = np.squeeze(scores[indices])
classes = np.squeeze(classes[indices])
# Draw the results of the detection (aka 'visulaize the results')
vis_util.visualize_boxes_and_labels_on_image_array(
frame,
boxes,
classes,
scores,
category_index,
use_normalized_coordinates=True,
line_thickness=8,
min_score_thresh=0.70)
cv2.putText(frame,"FPS: {0:.2f}".format(frame_rate_calc),(30,50),font,1,(255,255,0),2,cv2.LINE_AA)
#print(category_index)
try:
app = firebase_admin.get_app()
except ValueError as e:
cred = credentials.Certificate("./ServiceAccountKey.json")
app = firebase_admin.initialize_app(cred)
store = firestore.client()
#doc_ref = store.collection(u'users').limit(2)
print(len(boxes.shape))
totalcount= boxes.shape[1]
#x = re.search('[\w]', str(totalcount))
#totalcount = x.group()
print("Il y'a {0} personne dans la salle".format(totalcount))
# All the results have been drawn on the frame, so it's time to display it.
store.collection(u'Piece').document(u'Cuisine').set({u'nbrPers': int(totalcount)})
cv2.putText(frame,"NbrPerson"+str(totalcount) ,(50, 45),font,0.8,(0, 0xFF, 0xFF),2,cv2.FONT_HERSHEY_SIMPLEX,)
cv2.imshow('Object detector', frame)
t2 = cv2.getTickCount()
time1 = (t2-t1)/freq
frame_rate_calc = 1/time1
# Press 'q' to quit
if cv2.waitKey(1) == ord('q'):
break
rawCapture.truncate(0)
camera.close()