Example #1
0
def openpose_demo(canvas):
    # Custom Params (refer to include/openpose/flags.hpp for more parameters)
    params = dict()
    params["model_folder"] = "../../../models/"
    params["hand"] = True

    # Starting OpenPose
    opWrapper = op.WrapperPython()
    opWrapper.configure(params)
    opWrapper.start()

    cap = cv2.VideoCapture(0)

    before_form = []
    current_form = []
    counter = 0
    global rootFlag
    while (True):
        ret, frame = cap.read()

        # Process Image
        datum = op.Datum()
        imageToProcess = frame
        datum.cvInputData = imageToProcess

        opWrapper.emplaceAndPop([datum])

        cv2.imshow("OpenPose 1.5.0 - Tutorial Python API", datum.cvOutputData)

        #print(datum.handKeypoints[1][0])

        right_hand, flag = hm.is_hand_recog(datum.handKeypoints[1][0])
        if flag == True:
            current_form = hm.check_handform2(right_hand)
            #print(current_form,counter)
            if current_form == before_form:  #1フレーム前の形と現在の形を比較する
                counter = counter + 1  #同じだったらカウントを1増やす
                if (counter == 10):  #カウントが10になったら(10回連続して同じ形を認識したら)
                    canvas.delete("all")
                    n = hm.list_to_num(current_form)  #手の形から番号を決定
                    try:

                        canvas.create_text(300, 300, text=n, font=('', 350))
                    except Exception as e:
                        break
            else:
                counter = 0  #違ったらカウントをリセットする
            before_form = current_form
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
        if rootFlag == False:
            break
    cap.release()
    cv2.destroyAllWindows()
Example #2
0
    def update(self):

        ret,frame = self.cap.read()
        # Process Image
        datum = op.Datum()
        imageToProcess = frame
        datum.cvInputData = imageToProcess

        self.opWrapper.emplaceAndPop([datum])
        cv2.namedWindow("OpenPose 1.5.0 - Tutorial Python API", cv2.WINDOW_KEEPRATIO | cv2.WINDOW_NORMAL) #ウィンドウサイズを可変に
        cv2.imshow("OpenPose 1.5.0 - Tutorial Python API", datum.cvOutputData)


        right_hand,flag = hm.is_hand_recog(datum.handKeypoints[1][0])


        self.current_form = hm.check_handform2(right_hand)
        if self.current_form == self.before_form:   #1フレーム前の形と現在の形を比較する
            self.counter = self.counter + 1  #同じだったらカウントを1増やす
            if(self.counter == 5): #カウントが10になったら(10回連続して同じ形を認識したら)
                n = hm.list_to_num(self.current_form) #手の形から番号を決定
                print(n)
        else:
            self.counter = 0 #違ったらカウントをリセットする
        self.before_form = self.current_form

        if self.onoff:

            if pyxel.btnr(pyxel.KEY_RIGHT):
                self.now = changechannel(self.now,1)
            if pyxel.btnr(pyxel.KEY_LEFT):
                self.now = changechannel(self.now,-1)
            if pyxel.btnr(pyxel.KEY_UP):
                pyxel.cls(channelToImage(self.channel[self.now]))
                pyxel.text(int(pyxel.width)-5, 5, str(self.channel[self.now]), 0)
                self.vol = volumeChange(self.vol,1)
                self.volcon = 50


            if pyxel.btnr(pyxel.KEY_DOWN):
                pyxel.cls(channelToImage(self.channel[self.now]))
                pyxel.text(int(pyxel.width)-5, 5, str(self.channel[self.now]), 0)
                self.vol = volumeChange(self.vol,-1)
                self.volcon = 50

        if pyxel.btnr(pyxel.KEY_O) and self.onoff==True:
            self.onoff = False
            self.range = int(pyxel.height/2)
            self.volcon = 0

        if pyxel.btnr(pyxel.KEY_I) and self.onoff==False:
            self.onoff = True
            self.range = 0
            print(self.onoff)
Example #3
0
def openpose_demo(canvas):
    # Custom Params (refer to include/openpose/flags.hpp for more parameters)
    params = dict()
    params["model_folder"] = "../../../models/"
    params["hand"] = True

    # Starting OpenPose
    opWrapper = op.WrapperPython()
    opWrapper.configure(params)
    opWrapper.start()

    cap = cv2.VideoCapture(0)  #0だったり1だったり
    #cap.set(3,1280)
    #cap.set(4,960)
    cap.set(3, 1920)
    cap.set(4, 1080)

    before_form = []
    current_form = []
    counter = 0
    global rootFlag
    while (True):
        ret, frame = cap.read()
        #cv2.imshow('Raw Frame', frame)
        #frame = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
        #frame = cv2.cvtColor(frame,cv2.COLOR_GRAY2RGB)

        #frame = adjust(frame,alpha=1.0,beta=-25.0)

        # Process Image
        datum = op.Datum()
        imageToProcess = frame
        datum.cvInputData = imageToProcess

        opWrapper.emplaceAndPop([datum])

        cv2.namedWindow("OpenPose 1.5.0 - Tutorial Python API",
                        cv2.WINDOW_KEEPRATIO
                        | cv2.WINDOW_NORMAL)  #ウィンドウサイズを可変に
        cv2.imshow("OpenPose 1.5.0 - Tutorial Python API", datum.cvOutputData)

        #print(datum.handKeypoints[1][0])
        try:
            right_hand, flag = hm.is_hand_recog(datum.handKeypoints[1][0])
        except Exception as e:
            continue
        #カメラの指定によっては「IndexError: too many indices for array」というエラーが出る

        if flag == True:
            current_form = hm.check_handform2(right_hand)
            print(hm.list_to_num(current_form))
            if current_form == before_form:  #1フレーム前の形と現在の形を比較する
                counter = counter + 1  #同じだったらカウントを1増やす
                if (counter == 5):  #カウントが10になったら(10回連続して同じ形を認識したら)
                    canvas.delete("all")
                    n = hm.list_to_num(current_form)  #手の形から番号を決定
                    #if n == '5':
                    #    response = requests.post('https://api.nature.global/1/signals/c0035911-6e5d-43c5-a965-c11dcebcf924/send', headers=headers, verify=False)
                    #if n == '4':
                    #    response = requests.post('https://api.nature.global/1/signals/00db0c08-6677-410a-bb65-4f2edc7d47c8/send', headers=headers, verify=False)
                    #    response = requests.post('https://api.nature.global/1/signals/00db0c08-6677-410a-bb65-4f2edc7d47c8/send', headers=headers, verify=False)
                    #if n == '3':
                    #    response = requests.post('https://api.nature.global/1/signals/9ca9ac8e-8739-4dad-9e75-bf1f8a93b597/send', headers=headers, verify=False)
                    #    response = requests.post('https://api.nature.global/1/signals/9ca9ac8e-8739-4dad-9e75-bf1f8a93b597/send', headers=headers, verify=False)
                    try:
                        canvas.create_text(300, 300, text=n, font=('', 350))
                    except Exception as e:
                        break
            else:
                counter = 0  #違ったらカウントをリセットする
                try:
                    canvas.delete("all")
                except Exception as e:
                    break

            before_form = current_form
        else:
            canvas.delete("all")

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
        if rootFlag == False:
            break
    cap.release()
    cv2.destroyAllWindows()
def openpose_demo(canvas):
    # Custom Params (refer to include/openpose/flags.hpp for more parameters)
    params = dict()
    params["model_folder"] = "../../../models/"
    params["hand"] = True

    # Starting OpenPose
    opWrapper = op.WrapperPython()
    opWrapper.configure(params)
    opWrapper.start()

    upperbody_cascade_path = 'haarcascade_upperbody.xml'
    upperbody_cascade = cv2.CascadeClassifier(upperbody_cascade_path)
    cap = cv2.VideoCapture(0)  #0だったり1だったり

    before_form = []
    current_form = []
    counter = 0
    global rootFlag
    while (True):
        ret, frame = cap.read()

        frame = adjust(frame, alpha=1.0, beta=-25.0)

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        bodys = upperbody_cascade.detectMultiScale(gray,
                                                   minNeighbors=3,
                                                   minSize=(100, 100))
        max_x, max_y, max_h, max_w = max_body_select(bodys)
        print(max_x, max_y, max_h, max_w)

        #if max_h < 200:
        #    continue
        try:
            frame2 = frame[max_y - 20:max_y + max_h + 20,
                           max_x + 20:max_x + max_w + 20]
            #frame2 = scale_box(frame,640,480)
            cv2.imshow('Raw Frame', frame2)
            # Process Image
            datum = op.Datum()
            imageToProcess = frame2
            datum.cvInputData = imageToProcess

            opWrapper.emplaceAndPop([datum])

            cv2.namedWindow("OpenPose 1.5.0 - Tutorial Python API",
                            cv2.WINDOW_KEEPRATIO
                            | cv2.WINDOW_NORMAL)  #ウィンドウサイズを可変に
            cv2.imshow("OpenPose 1.5.0 - Tutorial Python API",
                       datum.cvOutputData)

            #print(datum.handKeypoints[1][0])
            try:
                right_hand, flag = hm.is_hand_recog(datum.handKeypoints[1][0])
            except Exception as e:
                continue
            #カメラの指定によっては「IndexError: too many indices for array」というエラーが出る

            if flag == True:
                current_form = hm.check_handform2(right_hand)
                #print(current_form,counter)
                if current_form == before_form:  #1フレーム前の形と現在の形を比較する
                    counter = counter + 1  #同じだったらカウントを1増やす
                    if (counter == 2):  #カウントが10になったら(10回連続して同じ形を認識したら)
                        canvas.delete("all")
                        n = hm.list_to_num(current_form)  #手の形から番号を決定
                        try:
                            canvas.create_text(300,
                                               300,
                                               text=n,
                                               font=('', 350))
                        except Exception as e:
                            break
                else:
                    counter = 0  #違ったらカウントをリセットする
                before_form = current_form

        except Exception as e:
            continue

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
        if rootFlag == False:
            break
    cap.release()
    cv2.destroyAllWindows()
def openpose_demo(canvas):
    # Custom Params (refer to include/openpose/flags.hpp for more parameters)
    upperbody_cascade = cv2.CascadeClassifier(upperbody_cascade_path)

    params = dict()
    params["model_folder"] = "../../../models/"
    params["hand"] = True

    # Starting OpenPose
    opWrapper = op.WrapperPython()
    opWrapper.configure(params)
    opWrapper.start()

    cap = cv2.VideoCapture(0)  #0だったり1だったり
    cap.set(3, 1280)
    cap.set(4, 960)

    before_form = []
    current_form = []
    counter = 0
    global rootFlag
    while (True):
        ret, frame = cap.read()

        frame = adjust(frame, alpha=1.0, beta=-25.0)

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        bodys = upperbody_cascade.detectMultiScale(gray)

        max_x, max_y, max_h, max_w = max_body_select(bodys)
        print(max_x, max_y, max_h, max_w)

        try:

            frame2 = frame[max_y:max_y + max_h, max_x:max_x + max_w]

            cv2.imshow("zoom image", frame2)

            # Process Image
            datum2 = op.Datum()
            datum2.cvInputData = frame2
            opWrapper.emplaceAndPop([datum2])

            #cv2.imshow("zoom image", datum2.cvOutputData)

            try:
                right_hand, flag = hm.is_hand_recog(datum2.handKeypoints[1][0])
            except Exception as e:
                continue
            #カメラの指定によっては「IndexError: too many indices for array」というエラーが出る

            if flag == True:
                current_form = hm.check_handform2(right_hand)
                #print(current_form,counter)
                if current_form == before_form:  #1フレーム前の形と現在の形を比較する
                    counter = counter + 1  #同じだったらカウントを1増やす
                    if (counter == 2):  #カウントが10になったら(10回連続して同じ形を認識したら)
                        canvas.delete("all")
                        n = hm.list_to_num(current_form)  #手の形から番号を決定
                        try:
                            canvas.create_text(300,
                                               300,
                                               text=n,
                                               font=('', 350))
                        except Exception as e:
                            break
                else:
                    counter = 0  #違ったらカウントをリセットする
                before_form = current_form
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
            if rootFlag == False:
                break

        except Exception as e:
            continue

    cap.release()
    cv2.destroyAllWindows()
def openpose_demo(canvas):
    # Custom Params (refer to include/openpose/flags.hpp for more parameters)
    params = dict()
    params["model_folder"] = "../../../models/"
    params["hand"] = True

    # Starting OpenPose
    opWrapper = op.WrapperPython()
    opWrapper.configure(params)
    opWrapper.start()

    kinect_ir = PyKinectRuntime.PyKinectRuntime(
        PyKinectV2.FrameSourceTypes_Infrared
        | PyKinectV2.FrameSourceTypes_Depth)
    kinect_color = PyKinectRuntime.PyKinectRuntime(
        PyKinectV2.FrameSourceTypes_Color | PyKinectV2.FrameSourceTypes_Body
        | PyKinectV2.FrameSourceTypes_Depth)
    depth_width, depth_height = kinect_ir.depth_frame_desc.Width, kinect_ir.depth_frame_desc.Height

    before_form = []
    current_form = []
    counter = 0
    global rootFlag
    while (True):

        frame_ir = kinect_ir.get_last_infrared_frame()
        frame_ir = np.uint8(frame_ir.clip(1, 4080) / 16.)
        frame_ir = np.reshape(frame_ir,
                              (depth_height, depth_width)).astype(np.uint8)
        ret, thresh1 = cv2.threshold(frame_ir, 130, 255, cv2.THRESH_BINARY)
        thresh1 = correction(thresh1)
        thresh1 = cv2.cvtColor(thresh1, cv2.COLOR_GRAY2RGB)
        M = np.float32([[1, 0, 7], [0, 1, 0]])
        kernel = np.ones((5, 5), np.uint8)
        thresh1 = cv2.dilate(thresh1, kernel, iterations=1)
        thresh1 = cv2.warpAffine(thresh1, M, (512, 424))

        frame_color = kinect_color.get_last_color_frame()
        frame_color = frame_color.reshape((1080, 1920, -1)).astype(np.uint8)
        scale = max(512 / frame_color.shape[1], 424 / frame_color.shape[0])
        frame_color = cv2.resize(frame_color, dsize=None, fx=scale, fy=scale)
        frame_color = frame_color[:, 121:633]
        frame_color = cv2.cvtColor(frame_color, cv2.COLOR_RGBA2RGB)

        frame = cv2.bitwise_and(frame_color, thresh1)

        frame_ir = None
        frame_color = None

        # Process Image
        datum = op.Datum()
        imageToProcess = frame
        datum.cvInputData = imageToProcess

        opWrapper.emplaceAndPop([datum])

        cv2.namedWindow("OpenPose 1.5.0 - Tutorial Python API",
                        cv2.WINDOW_KEEPRATIO
                        | cv2.WINDOW_NORMAL)  #ウィンドウサイズを可変に
        cv2.imshow("OpenPose 1.5.0 - Tutorial Python API", datum.cvOutputData)

        #print(datum.handKeypoints[1][0])
        try:
            right_hand, flag = hm.is_hand_recog(datum.handKeypoints[1][0])
        except Exception as e:
            continue
        #カメラの指定によっては「IndexError: too many indices for array」というエラーが出る

        if flag == True:
            current_form = hm.check_handform2(right_hand)
            print(hm.list_to_num(current_form))
            #print(current_form,counter)
            if current_form == before_form:  #1フレーム前の形と現在の形を比較する
                counter = counter + 1  #同じだったらカウントを1増やす
                if (counter == 2):  #カウントが10になったら(10回連続して同じ形を認識したら)
                    canvas.delete("all")
                    n = hm.list_to_num(current_form)  #手の形から番号を決定
                    try:
                        canvas.create_text(300, 300, text=n, font=('', 350))
                    except Exception as e:
                        break
            else:
                counter = 0  #違ったらカウントをリセットする
            before_form = current_form
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
        if rootFlag == False:
            break
    cap.release()
    cv2.destroyAllWindows()
Example #7
0
while (True):
    ret, frame = cap.read()

    # Process Image
    datum = op.Datum()
    imageToProcess = frame
    datum.cvInputData = imageToProcess

    opWrapper.emplaceAndPop([datum])

    cv2.imshow("OpenPose 1.5.0 - Tutorial Python API", datum.cvOutputData)

    #print(datum.handKeypoints[1][0])

    right_hand, flag = hm.is_hand_recog(datum.handKeypoints[1][0])
    if flag == True:
        current_form = hm.check_handform2(right_hand)
        #print(current_form,counter)
        if current_form == before_form:
            counter = counter + 1
            if (counter == 10):
                print(hm.list_to_num(current_form))
        else:
            counter = 0
        before_form = current_form
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
Example #8
0
def openpose_demo():
    # Custom Params (refer to include/openpose/flags.hpp for more parameters)
    params = dict()
    params["model_folder"] = "../../../models/"
    params["hand"] = True

    # Starting OpenPose
    opWrapper = op.WrapperPython()
    opWrapper.configure(params)
    opWrapper.start()

    cap = cv2.VideoCapture(0)  #0だったり1だったり
    #cap.set(3,1280)
    #cap.set(4,960)
    cap.set(3, 1920)
    cap.set(4, 1080)

    before_form = []
    current_form = []
    counter = 0
    global rootFlag
    while (True):
        ret, frame = cap.read()

        # Process Image
        datum = op.Datum()
        imageToProcess = frame
        datum.cvInputData = imageToProcess

        opWrapper.emplaceAndPop([datum])

        cv2.namedWindow("OpenPose 1.5.0 - Tutorial Python API",
                        cv2.WINDOW_KEEPRATIO
                        | cv2.WINDOW_NORMAL)  #ウィンドウサイズを可変に
        cv2.imshow("OpenPose 1.5.0 - Tutorial Python API", datum.cvOutputData)

        #print(datum.handKeypoints[1][0])
        try:
            right_hand, flag = hm.is_hand_recog(datum.handKeypoints[1][0])
        except Exception as e:
            continue
        #カメラの指定によっては「IndexError: too many indices for array」というエラーが出る

        if flag == True:
            current_form = hm.check_handform2(right_hand)
            #print(current_form)
            if current_form == before_form:  #1フレーム前の形と現在の形を比較する
                counter = counter + 1  #同じだったらカウントを1増やす
                if (counter == 5):  #カウントが10になったら(10回連続して同じ形を認識したら)
                    n = hm.list_to_num(current_form)  #手の形から番号を決定
                    if n == '5':
                        global onoff
                        if onoff:
                            onoff = False
                        else:
                            onoff = True
                    if n == '4':
                        pass
                    if n == '3':
                        pass

            else:
                counter = 0  #違ったらカウントをリセットする
            before_form = current_form
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cap.release()
    cv2.destroyAllWindows()
def openpose_demo(canvas):
    # Custom Params (refer to include/openpose/flags.hpp for more parameters)
    params = dict()
    params["model_folder"] = "../../../models/"
    params["hand"] = True

    # Starting OpenPose
    opWrapper = op.WrapperPython()
    opWrapper.configure(params)
    opWrapper.start()

    kinect = PyKinectRuntime.PyKinectRuntime(
        PyKinectV2.FrameSourceTypes_Infrared)
    depth_width, depth_height = kinect.depth_frame_desc.Width, kinect.depth_frame_desc.Height

    before_form = []
    current_form = []
    counter = 0
    global rootFlag
    while (True):
        frame = kinect.get_last_infrared_frame()
        frame = np.uint8(frame.clip(1, 4080) / 16.)
        frame = np.reshape(frame, (depth_height, depth_width)).astype(np.uint8)
        frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)

        # Process Image
        datum = op.Datum()
        imageToProcess = frame
        datum.cvInputData = imageToProcess

        opWrapper.emplaceAndPop([datum])

        cv2.namedWindow("OpenPose 1.5.0 - Tutorial Python API",
                        cv2.WINDOW_KEEPRATIO
                        | cv2.WINDOW_NORMAL)  #ウィンドウサイズを可変に
        cv2.imshow("OpenPose 1.5.0 - Tutorial Python API", datum.cvOutputData)

        #print(datum.handKeypoints[1][0])
        try:
            right_hand, flag = hm.is_hand_recog(datum.handKeypoints[1][0])
        except Exception as e:
            continue
        #カメラの指定によっては「IndexError: too many indices for array」というエラーが出る

        if flag == True:
            current_form = hm.check_handform2(right_hand)
            print(hm.list_to_num(current_form))
            #print(current_form,counter)
            if current_form == before_form:  #1フレーム前の形と現在の形を比較する
                counter = counter + 1  #同じだったらカウントを1増やす
                if (counter == 2):  #カウントが10になったら(10回連続して同じ形を認識したら)
                    canvas.delete("all")
                    n = hm.list_to_num(current_form)  #手の形から番号を決定
                    try:
                        canvas.create_text(300, 300, text=n, font=('', 350))
                    except Exception as e:
                        break
            else:
                counter = 0  #違ったらカウントをリセットする
            before_form = current_form
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
        if rootFlag == False:
            break
    cv2.destroyAllWindows()