Example #1
0
    def man_calib(self):
        try:
            self.pts_rgb = get_points(0)
            self.pts_depth = get_points(1)
            self.ref_depth_no_balls = four_point_transform(
                get_depth(), self.pts_depth)
            self.ref_rgb_no_balls = four_point_transform(
                get_video(), self.pts_rgb)
            with open('pts_rgb.pkl', 'wb') as output1:
                pickle.dump(self.pts_rgb, output1)

            with open('pts_depth.pkl', 'wb') as output2:
                pickle.dump(self.pts_depth, output2)

            cv2.imwrite('ref_depth_no_balls.png', self.ref_depth_no_balls)
            cv2.imwrite('ref_rgb_no_balls.png', self.ref_rgb_no_balls)

            self.quit()
        except ValueError:
            self.quit()
Example #2
0
def get_points(imgType=0):
    global refPt, image, i

    if imgType == 0:
        image = get_video()
    else:
        image = get_depth()

    clone = image.copy()
    cv2.namedWindow("image")
    cv2.setMouseCallback("image", click_and_crop)

    # keep looping until the 'q' key is pressed
    while True:
        # display the image and wait for a keypress
        cv2.imshow("image", image)
        key = cv2.waitKey(1) & 0xFF

        # if the 'r' key is pressed, reset the cropping region
        if key == ord("r"):
            image = clone.copy()
            refPt = []
            i = 0

        # if the 'c' key is pressed, break from the loop
        elif key == ord("c"):
            break

    # print(refPt)
    pts_order = order_points(np.array(refPt).reshape((4, 2)))
    # print(pts_order)
    warped = four_point_transform(image, pts_order)
    cv2.imshow("ROI", warped)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    refPt = []
    i = 0
    return pts_order
Example #3
0
def get_depth(pts):
    array, _ = freenect.sync_get_depth()
    array = array.astype(np.uint8)
    return four_point_transform(array, pts)
Example #4
0
def get_video(pts):
    array, _ = freenect.sync_get_video()
    array = cv2.cvtColor(array, cv2.COLOR_RGB2BGR)
    return four_point_transform(array, pts)
Example #5
0
    h_lines, v_lines = segment_lines(lines, delta)

    cv2.imshow(
        "Segmented Hough Lines",
        imutils.resize(drawHoughLines(imgs_copy[0], h_lines, v_lines),
                       height=320))

    _, _, req_corners, req_lines = find_req_lines(imgs_copy[0], h_lines,
                                                  v_lines, x_c, y_c)
    cv2.imshow("req intersections", imutils.resize(req_lines, height=320))

    corners = np.array(list(req_corners), dtype="float32")
    print(corners.shape)

    imgFinal = get_img()
    warped = four_point_transform(imgFinal, corners)
    cv2.imshow("warped", imutils.resize(warped, height=250))

    depthImg = get_depth()
    Np = 1
    # for i in range(Np):
    #    depthImg = depthImg + cv2.cvtColor(get_img(), cv2.COLOR_BGR2GRAY)
    #    print(depthImg[35, 35])

    cv2.imshow("origDepth", imutils.resize(depthImg, height=320))
    warped = four_point_transform(depthImg, corners)
    cv2.imshow("warpedDepth", imutils.resize(warped, height=250))
    b = time.time()

    print(b - a)
    cv2.waitKey()
Example #6
0
 def get_depth(self):
     array, _ = freenect.sync_get_depth()
     array = array.astype(np.uint8)
     return cv2.GaussianBlur(four_point_transform(array, self.pts_depth),
                             (5, 5), 3)