Spaces:
Configuration error
Configuration error
Download fps_example.py from Ibtehaj10/cheating-detection: direct link, hf CLI and curl.
- Browser
- Download file 839 Bytes
-
https://huggingface.co/spaces/Ibtehaj10/cheating-detection/resolve/main/fps_example.py
- Command line
-
hf download hf://spaces/Ibtehaj10/cheating-detection/fps_example.py
-
curl -L -o fps_example.py https://huggingface.co/spaces/Ibtehaj10/cheating-detection/resolve/main/fps_example.py
839 Bytes
| import cv2 | |
| import datetime | |
| import imutils | |
| def main(): | |
| cap = cv2.VideoCapture('test_video.mp4') | |
| fps_start_time = datetime.datetime.now() | |
| fps = 0 | |
| total_frames = 0 | |
| while True: | |
| ret, frame = cap.read() | |
| frame = imutils.resize(frame, width=800) | |
| total_frames = total_frames + 1 | |
| fps_end_time = datetime.datetime.now() | |
| time_diff = fps_end_time - fps_start_time | |
| if time_diff.seconds == 0: | |
| fps = 0.0 | |
| else: | |
| fps = (total_frames / time_diff.seconds) | |
| fps_text = "FPS: {:.2f}".format(fps) | |
| cv2.putText(frame, fps_text, (5, 30), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255), 1) | |
| cv2.imshow("Application", frame) | |
| key = cv2.waitKey(1) | |
| if key == ord('q'): | |
| break | |
| cv2.destroyAllWindows() | |
| main() | |