Example #1
0
def main():
    width = 320
    height = 240
    # Structued Light instance list
    slins_list = [
        sl.Binary(),
        sl.Gray(),
        sl.XOR(),
        sl.Ramp(),
        sl.PhaseShifting(),
        sl.Stripe()
    ]
    # Structure Light name list
    slname_list = ["binary", "gray", "xor", "ramp", "phaseshifting", "stripe"]

    for slins, slname in zip(slins_list, slname_list):
        imlist = slins.generate((width, height))

        # Make directory if it doesn't exist
        dirname = slname + "{0}x{1}".format(width, height)
        if os.path.isdir(dirname) == False:
            os.makedirs(dirname)

        # Export images
        zero_pad = len(str(len(imlist)))
        for i, img in enumerate(imlist):
            filename = slname + str(i + 1).zfill(zero_pad) + ".png"
            cv2.imwrite(dirname + "/" + filename, img)
Example #2
0
def main():
    width = 320
    height = 240

    gray = sl.Gray()

    # x-coord
    imlist_pattern_x = gray.generate((width, height))
    img_index_x = gray.decode(imlist_pattern_x, thresh=127)

    # y-coord
    imlist_pattern_y = sl.transpose(gray.generate((height, width)))
    img_index_y = gray.decode(imlist_pattern_y, thresh=127)

    # Export correspondence table
    # x-coord only
    corr_table = sl.getCorrespondenceTable(img_index_x)
    np.savetxt("correspondence_x.csv", corr_table, delimiter=",")
    print("[cam_x cam_y prj_x]")
    print(corr_table)

    # both xy-coord
    corr_table = sl.getCorrespondenceTable(img_index_x, img_index_y)
    np.savetxt("correspondence_xy.csv", corr_table, delimiter=",")
    print("[cam_x cam_y prj_x prj_y]")
    print(corr_table)
Example #3
0
def main():
    width = 640
    height = 480

    cap = cv2.VideoCapture(1)  # External web camera
    gray = sl.Gray()

    # Generate and Decode x-coord
    # Generate
    imlist_posi_pat = gray.generate((width, height))
    imlist_nega_pat = sl.invert(imlist_posi_pat)

    # Capture
    imlist_posi_cap = [imshowAndCapture(cap, img) for img in imlist_posi_pat]
    imlist_nega_cap = [imshowAndCapture(cap, img) for img in imlist_nega_pat]

    # Decode
    img_index = gray.decode(imlist_posi_cap, imlist_nega_cap)

    # Visualize decode result
    img_correspondence = np.clip(img_index / width * 255.0, 0,
                                 255).astype(np.uint8)
    cv2.imshow("corresponnence map", img_correspondence)
    cv2.waitKey(0)
    cv2.imwrite("correspondence.png", img_correspondence)
    cv2.destroyAllWindows()
    cap.release()
Example #4
0
def main():
    width = 320
    height = 240

    gray = sl.Gray()

    # x-coord
    imlist_pattern_x = gray.generate((width, height))
    img_index_x = gray.decode(imlist_pattern_x, thresh=127)

    # y-coord
    imlist_pattern_y = sl.transpose(gray.generate((height, width)))
    img_index_y = gray.decode(imlist_pattern_y, thresh=127)

    # Export correspondence table
    # x-coord only
    campoints, prjpoints = sl.getCorrespondencePoints(img_index_x)
    print("x-coord only")
    print("campoints: ", campoints.shape)
    print(campoints)
    print("prjpoints: ", prjpoints.shape)
    print(prjpoints)

    # both xy-coord
    campoints, prjpoints = sl.getCorrespondencePoints(img_index_x, img_index_y)
    print("xy-coord only")
    print("campoints: ", campoints.shape)
    print(campoints)
    print("prjpoints: ", prjpoints.shape)
    print(prjpoints)
Example #5
0
def main():
    width = 640
    height = 480

    cap = cv2.VideoCapture(1)  # External web camera
    gray = sl.Gray()

    # Generate and Decode x-coord
    # Generate
    imlist_posi_x_pat = gray.generate((width, height))
    imlist_nega_x_pat = sl.invert(imlist_posi_x_pat)

    # Capture
    imlist_posi_x_cap = [
        imshowAndCapture(cap, img) for img in imlist_posi_x_pat
    ]
    imlist_nega_x_cap = [
        imshowAndCapture(cap, img) for img in imlist_nega_x_pat
    ]

    # Decode
    img_index_x = gray.decode(imlist_posi_x_cap, imlist_nega_x_cap)

    # Generate and Decode y-coord
    # Generate
    imlist = gray.generate((height, width))
    imlist_posi_y_pat = sl.transpose(imlist)
    imlist_nega_y_pat = sl.invert(imlist_posi_y_pat)

    # Capture
    imlist_posi_y_cap = [
        imshowAndCapture(cap, img) for img in imlist_posi_y_pat
    ]
    imlist_nega_y_cap = [
        imshowAndCapture(cap, img) for img in imlist_nega_y_pat
    ]

    # Decode
    img_index_y = gray.decode(imlist_posi_y_cap, imlist_nega_y_cap)

    # Write correspondence table
    corr_table = sl.getCorrespondenceTable(img_index_x, img_index_y)
    np.savetxt("correspondence.csv", corr_table, delimiter=",")

    # Visualize decode result
    img_correspondence = cv2.merge([
        0.0 * np.zeros_like(img_index_x), img_index_x / width,
        img_index_y / height
    ])
    img_correspondence = np.clip(img_correspondence * 255.0, 0,
                                 255).astype(np.uint8)
    cv2.imshow("x:Green, y:Red", img_correspondence)
    cv2.waitKey(0)
    cv2.imwrite("correspondence.png", img_correspondence)
    cv2.destroyAllWindows()
    cap.release()
def main():
    width = 640
    height = 480

    gray = sl.Gray()

    imlist_pattern = gray.generate((width, height))

    print("1. Simple thresholding")
    img_index = gray.decode(imlist_pattern, thresh=127)

    print("2. Per-pixel thresholding")
    img_white = np.full((height, width), 255, dtype=np.uint8)
    img_black = np.full((height, width), 0, dtype=np.uint8)
    img_thresh = 0.5 * img_white + 0.5 * img_black
    img_index = gray.decode(imlist_pattern, thresh=img_thresh)

    print("3. Posi-Nega comparing")
    imlist_posi = imlist_pattern
    imlist_nega = sl.invert(imlist_posi)
    img_index = gray.decode(imlist_posi, imlist_nega)