- Project Type:
- Operating System & Browser: - MAC OS - google chrome
- Project Universe Link or Workspace/Project ID: - fnl_labeling
Objective: I am trying to export the JSON dictionaries of my frame predictions using code in python. I found this script on the roboflow forum from a couple years back.
Error: I was successful at obtaining the predictions for a couple frames, but then I ran into an http error. My video is around 2min~
Looking at the other forums, it seems as though I may need to pay more for this function to work, but I wanted to confirm before doing so.
roboflow.login()
rf = roboflow.Roboflow()
rf = Roboflow(api_key="xxx")
project = rf.workspace("caitlyn-lee-gr-dartmouth-edu").project("xxx")
version = project.version(1)
# run inference
model = version.model
# Video capture
f = cv2.VideoCapture(video_file)
rf = Roboflow(api_key="f06RVtgEWRnqjdc52Ujc")
project = rf.workspace("fnlidentitylabels").project("fnl-character-labeling")
model = project.version(5).model
dataset = version.download("yolov4pytorch")
while(f.isOpened()):
# f.read() methods returns a tuple, first element is a bool
# and the second is frame
ret, frame = f.read()
if ret == True:
# save frame as a “temporary” jpeg file
cv2.imwrite('temp.jpg', frame)
# run inference on “temporary” jpeg file (the frame)
predictions = model.predict('temp.jpg')
predictions_json = predictions.json()
# printing all detection results from the image
print(predictions_json)
# accessing individual predicted boxes on each image
for bounding_box in predictions:
# x0 = bounding_box['x'] - bounding_box['width'] / 2#start_column
# x1 = bounding_box['x'] + bounding_box['width'] / 2#end_column
# y0 = bounding_box['y'] - bounding_box['height'] / 2#start row
# y1 = bounding_box['y'] + bounding_box['height'] / 2#end_row
class_name = bounding_box['class']
confidence_score = bounding_box['confidence']
detection_results = bounding_box
class_and_confidence = (class_name, confidence_score)
print(class_and_confidence, '\n')
elif cv.waitKey(1) == ord('q'):
break
else:
break
f.release()
cv2.destroyAllWindows()