Ejemplo n.º 1
0
def checkPositionDepthAndRGB(rgb, depth_transformed, depth):

    imgConts, conts = MiniUtils.getContours(rgb, depth_transformed)
    for i in conts:
        x, y, w, h = i[3]
        #print('RGB:%d DepthTrans: %d', np.size(rgb), np.size(depth_transformed))
        print(depth_transformed[x][y])
        '''
Ejemplo n.º 2
0
def main():
    k4a = PyK4A(
        Config(
            color_resolution=pyk4a.ColorResolution.RES_720P,
            color_format=pyk4a.ImageFormat.COLOR_BGRA32,
            depth_mode=pyk4a.DepthMode.NFOV_UNBINNED,
            synchronized_images_only=True,
        ))

    k4a.start()
    # getters and setters directly get and set on device
    k4a.whitebalance = 4500
    assert k4a.whitebalance == 4500
    k4a.whitebalance = 4510
    assert k4a.whitebalance == 4510
    windowID = ''  #Give id to the windows to know which to destroy when not needed
    BODY_PARTS = {
        "Nose": 0,
        "Neck": 1,
        "RShoulder": 2,
        "RElbow": 3,
        "RWrist": 4,
        "LShoulder": 5,
        "LElbow": 6,
        "LWrist": 7,
        "RHip": 8,
        "RKnee": 9,
        "RAnkle": 10,
        "LHip": 11,
        "LKnee": 12,
        "LAnkle": 13,
        "REye": 14,
        "LEye": 15,
        "REar": 16,
        "LEar": 17,
        "Background": 18
    }

    POSE_PAIRS = [["Neck", "RShoulder"], ["Neck", "LShoulder"],
                  ["RShoulder", "RElbow"], ["RElbow", "RWrist"],
                  ["LShoulder", "LElbow"], ["LElbow", "LWrist"],
                  ["Neck", "RHip"], ["RHip", "RKnee"], ["RKnee", "RAnkle"],
                  ["Neck", "LHip"], ["LHip", "LKnee"], ["LKnee", "LAnkle"],
                  ["Neck", "Nose"], ["Nose", "REye"], ["REye", "REar"],
                  ["Nose", "LEye"], ["LEye", "LEar"]]

    net = cv2.dnn.readNetFromTensorflow("graph_opt.pb")  ##weights
    inWidth = 654
    inHeight = 368
    thr = 0.2
    while 1:
        capture = k4a.get_capture()

        if np.any(capture.color) and np.any(capture.depth):
            checker, frame, length = bodyTracking(capture.color, net, inWidth,
                                                  inHeight, BODY_PARTS,
                                                  POSE_PAIRS, thr)
            frame_depth = np.clip(capture.depth, 0, 2**10 - 1)
            frame_depth >>= 2
            num_fingers, img_draw = handEstimator(frame_depth)
            imgConts, conts = MiniUtils.getContours(capture.color,
                                                    capture.transformed_depth,
                                                    filter=4)
            cv2.imshow('Hand', img_draw)
            cv2.imshow('rgb', capture.color)
            '''if checker:
                if length < 11:
                    if windowID != '01' and windowID != '':
                        cv2.destroyAllWindows()
                    cv2.imshow('Hand', img_draw)
                    windowID = '01'
                else:
                    if windowID != '10' and windowID != '':
                        cv2.destroyAllWindows()
                    cv2.imshow('Body', frame)
                    windowID = '10'
            else:
                cv2.imshow('Conts', imgConts)
                if windowID != '11' and windowID != '':
                    cv2.destroyAllWindows()
                windowID = '11'
                '''
            key = cv2.waitKey(1)
            if key == ord('q'):
                cv2.destroyAllWindows()
                break
    k4a.stop()
Ejemplo n.º 3
0
def main():
    '''cv2.namedWindow("Trackbars")

    cv2.createTrackbar("L-H", "Trackbars", 0, 255, nothing)
    cv2.createTrackbar("L-S", "Trackbars", 0, 255, nothing)
    cv2.createTrackbar("L-V", "Trackbars", 0, 255, nothing)
    cv2.createTrackbar("U-H", "Trackbars", 0, 255, nothing)
    cv2.createTrackbar("U-S", "Trackbars", 0, 255, nothing)
    cv2.createTrackbar("U-V", "Trackbars", 0, 255, nothing)'''

    wP = 210
    hP = 297
    scale = 3

    img = cv2.imread('colorimg.bmp')
    depth = cv2.imread('depth.bmp')
    #cv2.rectangle(img, (489, 269), (612, 344), (0, 255, 0), 2)
    slot0 = [[489, 269], [612, 269], [489, 344], [612, 344]] #slot0
    slot0_mP = [550.5, 306.5]
    #cv2.rectangle(img, (645, 273), (780, 350), (0, 255, 0), 2)
    slot1 = [[645, 273], [780, 273], [645, 350], [780, 350]]#slot1
    slot1_mP = [712.5, 311.5]
    #cv2.rectangle(img, (805, 271), (920, 346), (0, 255, 0), 2)
    slot2= [[805, 271], [920, 271], [805, 346], [920, 346]]#slot2
    slot2_mP = [862.5, 308.5]
    #cv2.rectangle(img, (483, 377), (599, 470), (0, 255, 0), 2)
    slot3 = [[483, 377], [599, 377], [483, 470], [599, 470]]#slot3
    slot3_mP = [541, 423.5]
    #cv2.rectangle(img, (645, 377), (792, 474), (0, 255, 0), 2)
    slot4 = [[645, 377], [792, 377], [645, 474], [792, 474]]#slot4
    slot4_mP = [718.5, 425.5]
    #cv2.rectangle(img, (825, 382), (949, 475), (0, 255, 0), 2)
    slot5 = [[825, 382], [949, 382], [825, 475], [949, 475]]#slot5
    slot5_mP = [887, 428.5]
    slots = [slot0, slot1, slot2, slot3, slot4, slot5]
    midpointsSlots = [slot0_mP, slot1_mP, slot2_mP, slot3_mP, slot4_mP, slot5_mP]
    imgConts, conts = MiniUtils.getContours(img, depth, filter=4, showCanny=True)
    midpointsConts = MiniUtils.midPoints(conts)
    '''frame_depth = np.clip(capture.depth, 0, 2 ** 10 - 1)
    frame_depth >>= 2
    num_fingers, img_draw = handEstimator(frame_depth)
    if len(conts) > 0:
        switcher = {
            0: goalPosition[0] = [midpointsSlots[0], midpointsConts.pop(0)]
            1: goalPosition[1] = [midpointsSlots[1], midpointsConts.pop(0)]
            2: goalPosition[2] = [midpointsSlots[2], midpointsConts.pop(0)]
            3: goalPosition[3] = [midpointsSlots[3], midpointsConts.pop(0)]
            4: goalPosition[4] = [midpointsSlots[4], midpointsConts.pop(0)]
            5: goalPosition[5] = [midpointsSlots[5], midpointsConts.pop(0)]
            }
        switcher.get(num_fingers, 'Error')
        
    '''

    #print(len(conts))
    while 1:

        if len(conts) != 0:
            for obj in conts:
                cv2.polylines(imgConts, [obj[2]], True, (0, 255, 0), 2)
        #cv2.imshow('contss', imgConts)
        for slot in slots:
            cv2.rectangle(imgConts, (slot[0][0], slot[0][1]), (slot[3][0], slot[3][1]), (0, 255, 0), 2)
        cv2.imshow('img', img)
        key = cv2.waitKey(1)
        if key == ord('q'):
            cv2.destroyAllWindows()
            break