���ץƥ�����ե�����ʰץ���������ǧ�������Ѥ���
�������� Intel ���ǥץ������ RealSense D415 �� 3DiVi ���� Nuitrack SDK ���Ȥ߹�碌�ǥ���������ǧ�����Ƥ��ޤ���������ư��ˤϻ��Ӥ˿����� D415 �����˽���Υ���������ǥ��ޡ��Ⱦ���������ƥ��Ȥ����ͻҤ����Ƥ��ޤ���
���Τ褦�˴��Ԥɤ����ȿ����������ΤǤ��������Τ��Ȥ����ˤʤäƤ��ޤ�����
���Τ�����λ���� Kinect ��Ʊ���Τ褦�Ǥ������������ʤθ��Ф��Ӥ���Ŭ�ڤ˼��̤��뤿���ɬ�פǤ����������Ǥ�äȥ�դʤ�Τ⤢��Фȹͤ��ޤ��������ﴶ�ФǤϥ����Ĥ����Ĥˤ⤰�������ޤ޻������������Ȥʤ����äȻؼ���Ф��Ȥ��ä����Ȥ�Ǥ�������������Ǥ�������ʤ櫓�ǻ�˴�ñ�ʤ����ߤ��äƤߤ뤳�Ȥˤ��ޤ�����
�ͤ����Ȥ��ơ����������������Τ˽���ο��ʾ�ΰ�ư�򤶤ä��긡�Τ������ˤ��θ�����Ƚ�ꤹ�뤳�Ȥ����ꤷ�ޤ������¸���ˡ��ͤ��ʤ������Ǥ��������ä򤷤��Ȥ�������OpenCV �ǥ��ץƥ�����ե��������Ѥ��ƤϤɤ������פȤ����쥹�ݥ󥹤�����ޤ������긵�Ǥ��ȥ�å��� API �ʥ��: @nonbiri15 �ͤˤ��ɥ�����Ȥ������� ���Ƥ����Ȥ����ǥ��ץƥ�����ե����Τ��Ȥ��Τ餺�ˤ��ꡢ@icoxfog417 �ͤμ��ε��������Ӥ����礦�ɤ狼��䤹���ȤƤ⻲�ͤˤʤ�ޤ�����
�����֤�ư���β��ϤˤĤ��Ƥϡ��͡�����Ū�Ȥ����¸������ˡ������ޤ��������Ǥϡ��ޤ�Optical Flow��������ǤɤΤ褦�ʰ��֤Ť��ˤʤ�Τ��������Ƥ����ޤ���
:
�ʲ��� GitHub ��� OpenCV �����Υ���ץ�ץ������Ǥ�������� Dense��̩�˷��� Gunnar Farneback ˡ���Ѥ����Ƥ��ޤ���
����Ū�ʥ����֥����� PC ����³���Ƥ��Υץ�������¹Ԥ����ͻҤ�ʲ���ư��˼���Ƥ��ޤ������������������Τ�ư�����ʻ����κ�ɸ����������ª����Ƥ����ͻҤ����Ū��ɽ������ޤ���
���Υ���ץ�ץ������˾岼�����������ؤΰ�ư���ç¤ï¿½ï¿½È½ï¿½ê¤¹ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Ã¤ï¿½ï¿½Æ¤ß¤Þ¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Æ°ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Î¤ï¿½Æ°ï¿½î¤·ï¿½Þ¤ï¿½ï¿½ï¿½
��ɮ�����ץ������Υ����������ɤǤ����ޤ��ޤ����ɤ�;�ϤϤ����Τκ��󥪥ץƥ�����ե������������˿��줿���Ȥ��ç¤ï¿½Ê¼ï¿½ï¿½Ï¤Ç¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Ê»È¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Ç¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Ç¤ï¿½ï¿½ï¿½
#!/usr/bin/env python # -*- coding: utf-8 -*- # # ��̩�٥��ץƥ�����ե��������Ѥ����ʰץ���������ǧ���λ�� # # Web �������������������̤ˤĤ��� # Left, Right, Up, Down �������ؤΰ�ư���Τ������� # # OpenCV �����β�������ץ�˽������ɲä������ # https://github.com/opencv/opencv/blob/master/samples/python/opt_flow.py # # 2020-04 # import sys import time import numpy as np import cv2 # Í����ư�̤����� THRESHOLD_DETECT = 300 # �ڤ�ΤƤ����� THRESHOLD_IGNORE = 2 # ���ꥢ������������ x, y �����ؤ�����ư�� MOVE = [0, 0] # ��ưȯ�������� COUNT_MOVE = 0 # ľ��Υ��������㸡�Х����ƥ���� msec TIME_DETECT = 0 def millis(): return int(round(time.time() * 1000)) def put_header(img, str): cv2.putText(img, str, (26, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (255,0,0), 3) cv2.putText(img, str, (24, 48), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0,255), 3) # ���ꥤ�᡼���˹�̩�٥��ץƥ�����ե����Υ٥��ȥ�����Ťͤ������ʸ���� # ���碌�ƥ���������κ����岼 �������ؤΰ�ư������Ƚ�� def draw_flow(img, flow, step=16): global MOVE, COUNT_MOVE, TIME_DETECT # �������᡼���� Hight, Width h, w = img.shape[:2] # ���᡼���νIJ��������� step �ֳֻ���˴�Ť��IJ��ʻ�����ɸ����������� y, x = np.mgrid[step/2:h:step, step/2:w:step].reshape(2,-1).astype(int) # �ʻ�����ɸ�������Ƿ����б������ư����������� fx, fy = flow[y,x].T # �Ƴʻ���������Ȥ������褹����ʬ����ʥ٥��ȥ�ˤ���������� lines = np.vstack([x, y, x+fx, y+fy]).T.reshape(-1, 2, 2) lines = np.int32(lines + 0.5) vis = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) # ��ư�٥��ȥ��������� cv2.polylines(vis, lines, 0, (0, 255, 0)) #for (x1, y1), (_x2, _y2) in lines: # cv2.circle(vis, (x1, y1), 2, (0, 0, 255), -1) # ��ʬ��������������ǤˤĤ��� # �������齪���ޤǤ� x, y �������ؤΰ�ư�̤��߷פ����� vx = vy = 0 for i in range(len(lines)): val = lines[i][1][0]-lines[i][0][0] if abs(val) >= THRESHOLD_IGNORE: vx += val val = lines[i][1][1]-lines[i][0][1] if abs(val) >= THRESHOLD_IGNORE: vy += val # ����ư�̤˲û� MOVE[0] += vx MOVE[1] += vy # ��ư�̤��߷פ���������Ͱʾ�ʤ��ư���Ƚ�� if abs(vx) >= THRESHOLD_DETECT or abs(vy) >= THRESHOLD_DETECT: # ��ưȯ�������󥿤�û� COUNT_MOVE += 1 # ���������̤���ʤ��ư��λ���֤Ȳ��� else: mx = my = 0 if COUNT_MOVE > 0 and \ millis() - TIME_DETECT > 1000: # �������� # x, y �������ؤΰ�ư�̤�ʿ�Ѥ���� mx = int(MOVE[0]/COUNT_MOVE) my = int(MOVE[1]/COUNT_MOVE) # x, y ���������줫�ΰ�ư��ʿ�Ѥ���������Ͱʾ�ʤ� # �����岼�Τɤ������ؤΰ�ư����Ƚ�ꤷ��ɽ�� if abs(mx) >= THRESHOLD_DETECT or abs(my) >= THRESHOLD_DETECT: TIME_DETECT = millis() if abs(mx) >= abs(my): if mx >= 0: put_header(vis, 'LEFT') else: put_header(vis, 'RIGHT') else: if my >= 0: put_header(vis, 'DOWN') else: put_header(vis, 'UP') # ����ư�̤Ȱ�ưȯ�������󥿤ò¥¯¥ê¥¢ MOVE = [0, 0] COUNT_MOVE = 0 return vis def main(): cam = cv2.VideoCapture(0) # �ǽ�Υե졼����ɤ߹��� _ret, prev = cam.read() # ���쥤�������벽�����ݻ� prevgray = cv2.cvtColor(prev, cv2.COLOR_BGR2GRAY) while True: # �ե졼���ɤ߹��� _ret, img = cam.read() # ���쥤�������벽 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # ����ʬ�Ⱥ���ʬ�Υ��᡼�������̩�٥��ץƥ�����ե�������� flow = cv2.calcOpticalFlowFarneback(prevgray, gray, None, 0.5, 3, 15, 3, 5, 1.2, 0) # ����ʬ���ݻ����Ƥ��� prevgray = gray # flow ��Ļ벽 # https://docs.opencv.org/3.1.0/d7/d8b/tutorial_py_lucas_kanade.html """ hsv = np.zeros_like(img) hsv[...,1] = 255 mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1]) hsv[...,0] = ang*180/np.pi/2 hsv[...,2] = cv2.normalize(mag,None,0,255,cv2.NORM_MINMAX) rgb = cv2.cvtColor(hsv,cv2.COLOR_HSV2BGR) cv2.imshow('hsv', rgb) """ # �����˥ե����Υ٥��ȥ�����Ťͤ�ɽ�� cv2.imshow('flow', draw_flow(gray, flow)) ch = cv2.waitKey(1) if ch & 0xFF == ord('q') or ch == 27: # ESC break if __name__ == '__main__': main() cv2.destroyAllWindows()
(tanabe)