Closed ashannon018 closed 1 year ago
self answer .. (I resolved by myself.)
# STEP 2: Create an GestureRecognizer object.
VisionRunningMode = mp.tasks.vision.RunningMode
base_options = python.BaseOptions(model_asset_path='gesture_recognizer.task')
options = vision.GestureRecognizerOptions(base_options=base_options, running_mode=VisionRunningMode.VIDEO )
recognizer = vision.GestureRecognizer.create_from_options(options)
results = []
cap = cv2.VideoCapture(video_file_path)
fps = cv2.CAP_PROP_FPS
calc_timestamps = [0.0]
res_landmark = []
res_not_found_count = 0
ret = True
while ret:
ret, img = cap.read() # read one frame from the 'capture' object; img is (H, W, C)
if ret:
ts = cap.get(cv2.CAP_PROP_POS_MSEC)
cts = calc_timestamps[-1] + 1000/fps
#print(abs(ts-cts))
recognition_result =recognizer.recognize_for_video( mp.Image(image_format=ImageFormat.SRGB, data=img), int(ts))
try :
top_gesture = recognition_result.gestures[0][0]
hand_landmarks = top_gesture.category_name
#print(hand_landmarks)
results.append(top_gesture)
res_landmark.append(hand_landmarks)
except IndexError:
res_landmark.append('-')
res_not_found_count += 1
continue
cap.release()
cv2.destroyAllWindows
Hello, I've tried to read Video frame to numpy array. Did I missed something to make an input of recognizer?
==== Video Info. ===== <class 'numpy.ndarray'> W20230204 14:13:15.370810 88347 gesture_recognizer_graph.cc:122] Hand Gesture Recognizer contains CPU only ops. Sets HandGestureRecognizerGraph acceleartion to Xnnpack. I20230204 14:13:15.374961 88347 hand_gesture_recognizer_graph.cc:250] Custom gesture classifier is not defined.
TypeError Traceback (most recent call last) Cell In[10], line 35 33 frame_timestamp_ms = timearray[9] 34 print(type(buf[9])) ---> 35 mp_image = mp.Image(format=ImageFormat.SRGB, data=np.stack(buf[9])) 37 gesture_recognition_result = recognizer.recognize_for_video(mp_image,frame_timestamp_ms) 40 #numpy_frame_from_opencv = np.stack(frames, axis=0) # dimensions (T, H, W, C) 41 42 #print(len(numpy_frame_from_opencv))
TypeError: init(): incompatible constructor arguments. The following argument types are supported:
Invoked with: kwargs: format=<ImageFormat.SRGB: 1>, data=array([[[113, 123, 106], [113, 123, 106], [113, 123, 106], ..., [149, 162, 144], [149, 162, 144], [147, 160, 142]],