Пример #1
0
def main():
    capture = cv2.VideoCapture(0)
    isHandHist = False

    while capture.isOpened():
        ret, frame = capture.read()
        pressed_key = cv2.waitKey(1)

        if pressed_key & 0xFF == ord('q'):
            break
        elif pressed_key & 0xFF == ord('s'):
            rectangles = hp.get_rectangles(frame)
            handHist = hp.get_handHist(frame, rectangles)
            isHandHist = True
            cv2.destroyAllWindows()
        elif isHandHist:
            data, frame = hp.getPOI(frame, handHist)
            data = json.dumps(data)
            fileName = r'./hand_detection/handData.txt'
            fileData = open(fileName, 'w')
            fileData.write(data)
            fileData.close()

            cv2.imshow('Hand-tracker: END STREAM WITH \'q\'', frame)
        else:
            frame = hp.draw_rect(frame)
            frame = cv2.flip(frame, 1)
            cv2.imshow('Hand-scanner: SCAN HAND WITH \'s\'', frame)

    capture.release()
    cv2.destroyAllWindows()
Пример #2
0
def viewHandImg():
    capture = cv2.VideoCapture(0)

    while capture.isOpened():
        ret, frame = capture.read()
        pressed_key = cv2.waitKey(1)

        if pressed_key & 0xFF == ord('q'):
            break
        elif pressed_key & 0xFF == ord('s'):
            rectangles = hp.get_rectangles(frame)
            handHist = hp.get_handHist(frame, rectangles)
            while True:
                handImg = hp.getHandImg(frame, handHist)
                cv2.imshow('Hand', handImg) 
                ret, frame = capture.read()
                pressed_key = cv2.waitKey(1)
                if pressed_key & 0xFF == ord('q'):
                    capture.release()
                    break
        else:
            frame = hp.draw_rect(frame)
            frame = cv2.flip(frame, 1)
            cv2.imshow('Hand-scan', frame)

    capture.release()
    cv2.destroyAllWindows()
Пример #3
0
def viewContours():
    capture = cv2.VideoCapture(0)

    while capture.isOpened():
        ret, frame = capture.read()
        pressed_key = cv2.waitKey(1)

        if pressed_key & 0xFF == ord('q'):
            break
        elif pressed_key & 0xFF == ord('s'):
            rectangles = hp.get_rectangles(frame)
            handHist = hp.get_handHist(frame, rectangles)
            while True:
                handImg = hp.getHandImg(frame, handHist)
                contours = hp.getContours(handImg)
                largestContour = max(contours, key=cv2.contourArea) #hand outline
                cv2.drawContours(frame, largestContour, -1, [0, 255, 0], 3)
                handCentroid = hp.getCentroid(largestContour)

                #draw handCentroid
                radius = 5
                centroidColor = [255, 0, 0] 
                lineThickness = -1 #fill circle with -1 value
                cv2.circle(frame, handCentroid, radius, centroidColor, lineThickness)
                #cv2.drawContours(frame, contours, -1, [0, 0, 255], 3)
                cv2.imshow('Contours', frame)
                ret, frame = capture.read()
                pressed_key = cv2.waitKey(1)
                if pressed_key & 0xFF == ord('q'):
                    capture.release()
                    break
        else:
            frame = hp.draw_rect(frame)
            frame = cv2.flip(frame, 1)
            cv2.imshow('Hand-scan', frame)

    capture.release()
    cv2.destroyAllWindows()
Пример #4
0
def main():
    capture = cv2.VideoCapture(0)
    isHandHist = False

    while capture.isOpened():
        ret, frame = capture.read()
        pressed_key = cv2.waitKey(1)

        if pressed_key & 0xFF == ord('q'):
            break
        elif pressed_key & 0xFF == ord('s'):
            rectangles = hp.get_rectangles(frame)
            handHist = hp.get_handHist(frame, rectangles)
            isHandHist = True
        elif isHandHist:
            frame = hp.drawPOI(frame, handHist)
        else:
            frame = hp.draw_rect(frame)
            frame = cv2.flip(frame, 1)

        cv2.imshow('Live', frame)

    capture.release()
    cv2.destroyAllWindows()