def main(): # initialize the video stream and allow the camera sensor to warm up print("[INFO] starting video stream...") # cap = cv2.VideoCapture(0) vs = WebcamVideoStream(src=0).start() fps = FPS().start() #Notes the start time width = 440 with open("consumer_thread.csv", 'w', newline='') as file: writer = csv.writer(file) writer.writerow([ "Thread Frame #", "Time spent in reading the frame (seconds) from queue", "Time spent performing inference on the frame (seconds)" ]) # loop over the frames from the video stream #while True: while fps._numFrames < args["num_frames"]: # grab the frame from the threaded video stream and resize it # to have a maximum width of 400 pixels # Capture frame-by-frame start = timer() frame = vs.readFromQueue() end = timer() # if frame is not None then there was atleast one frame in queue # when read from the queue and returned. Else queue was empty. if frame is not None: # update the FPS counter fps.update() consumerThreadFrameNumber = fps._numFrames consumerThreadTimeTakenToReadThisFrame = (end - start) print( "[INFO] Consumer Thread : Time taken to read frame number", consumerThreadFrameNumber, "from queue is", consumerThreadTimeTakenToReadThisFrame, "seconds") height = frame.shape[0] dim = (width, height) frame = cv2.resize(frame, dim, interpolation=cv2.INTER_AREA) # detect faces in the frame and determine if they are wearing a # face mask or not startInferenceTime = timer() (locs, preds) = detect_and_predict_mask(frame, net, model) endInferenceTime = timer() consumerThreadTimeTakenToPerformInference = ( endInferenceTime - startInferenceTime) print( "[INFO] Consumer Thread : Time taken to performing inference on consumed frame number", consumerThreadFrameNumber, "is", consumerThreadTimeTakenToPerformInference, "seconds") writer.writerow([ consumerThreadFrameNumber, consumerThreadTimeTakenToReadThisFrame, consumerThreadTimeTakenToPerformInference ]) for (box, pred) in zip(locs, preds): # unpack the bounding box and predictions (startX, startY, endX, endY) = box (mask, withoutMask) = pred label = "Mask" if mask > withoutMask else "No Mask" color = (0, 255, 0) if label == "Mask" else (0, 0, 255) # include the probability in the label #label = "{}: {:.2f}%".format(label, max(mask, withoutMask) * 100) # display the label and bounding box rectangle on the output # frame cv2.putText(frame, label, (startX, startY - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.45, color, 2) cv2.rectangle(frame, (startX, startY), (endX, endY), color, 2) print("Showing frame") # show the output frame cv2.imshow("Output", frame) #cv2.destroyAllWindows() #key = cv2.waitKey(10) & 0xFF key = cv2.waitKey(1) & 0xFF # if the `q` key was pressed, break from the loop if key == ord("q"): break fps.stop() vs.stop() print("[INFO] elasped time: {:.2f}".format(fps.elapsed())) print("[INFO] approx. FPS: {:.2f}".format(fps.fps())) cv2.destroyAllWindows()
with open("consumer_thread_ip_camera.csv", 'w', newline='') as file: writer = csv.writer(file) writer.writerow([ "Thread Frame #", "Time spent in reading the frame (seconds) from queue", "Time spent performing inference on the frame (seconds)" ]) # loop over the frames from the video stream #while True: while fps._numFrames < args["num_frames"]: # grab the frame from the threaded video stream and resize it # to have a maximum width of 400 pixels # Capture frame-by-frame start = timer() frame = vs.readFromQueue() end = timer() # if frame is not None then there was atleast one frame in queue # when read from the queue and returned. Else queue was empty. if frame is not None: # update the FPS counter fps.update() consumerThreadFrameNumber = fps._numFrames consumerThreadTimeTakenToReadThisFrame = (end - start) print("[INFO] Consumer Thread : Time taken to read frame number", consumerThreadFrameNumber, "from queue is", consumerThreadTimeTakenToReadThisFrame, "seconds") height = frame.shape[0] dim = (width, height) frame = cv2.resize(frame, dim, interpolation=cv2.INTER_AREA) # detect faces in the frame and determine if they are wearing a