예제 #1
0
ren = calipy.vtkRenderer()
ren.addCamera("front_cam", cs=0.5)
ren.addCamera("back_cam", Rt.R, Rt.T, cs=0.5)

TV_width = 1.70
TV_height = 0.95

objectPoints = np.array([[0, 0, 0], [TV_width, 0, 0], [0, TV_height, 0],
                         [TV_width, TV_height, 0]]).astype(np.float64)

tvpoints_on_camera = TVRt.move(np.transpose(objectPoints))
ren.addLines("TV", np.transpose(tvpoints_on_camera), [0, 1, 3, 2, 0])
#ren.addCamera("TV_origin", TVRt.R, TVRt.T, cs=0.5)

# Display Input Image
cam = calipy.ColorCamera("./CameraData/back/cam_intrinsic.json")

input_img_path = "./display.jpg"
undistort_img_path = "undistort_display.jpg"

input_img = calipy.lib.imreadKorean(input_img_path)
undistort_img = cam.solveDistortion(input_img)
undistort_img = cv2.flip(undistort_img, 0)
cv2.imwrite(undistort_img_path, undistort_img)

uv_0 = np.dot(cam.intrinsic_inv, np.transpose([[0, 0, 1]]))
uv_1 = np.dot(cam.intrinsic_inv, np.transpose([[1920, 1080, 1]]))

uv_0 = 10 * uv_0 / uv_0[2]
uv_1 = 10 * uv_1 / uv_1[2]
예제 #2
0
import calipy

## Input
front_path = "./CameraData/Front/"
back_path = "./CameraData/back/"

## Output
output_path = "./CameraData/Rt.json"

front_data_list_seed = front_path + "*.png"
back_data_list_seed = back_path + "*.png"

front_intrinsic_path = front_path + "cam_intrinsic.json"
back_intrinsic_path = back_path + "cam_intrinsic.json"

front_cam = calipy.ColorCamera(front_intrinsic_path)
back_cam = calipy.ColorCamera(back_intrinsic_path)

### Init
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
criteria_cal = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 1e-5)

# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((3 * 4, 3), np.float32)
objp[:, :2] = np.mgrid[0:3, 0:4].T.reshape(-1, 2) * 0.135

# Arrays to store object points and image points from all the images.
objpoints = []  # 3d point in real world space
imgpoints_front = []  # 2d points in image plane.
imgpoints_back = []  # 2d points in image plane.
예제 #3
0
def runScreenUI(camera_path, img_path):
    cam = calipy.ColorCamera(camera_path)

    resize_value = 0.5
    original_img = cv2.imread(img_path)
    img = cam.solveDistortion(original_img)
    img = cv2.resize(img, (int(img.shape[1] * resize_value),int(img.shape[0] * resize_value)))

    sc = np.zeros((2,2,2))
    sc[0,0] = [0.202,0.262]
    sc[0,-1] = [0.816,0.28]
    sc[-1,0] = [0.204,0.783]
    sc[-1,-1] = [0.797,0.795]

    ui_selected_idx = -1

    while True:
        frame = img.copy()
        resize_img = drawScreen(frame, sc)
        cv2.imshow('frame',resize_img)
        chr = cv2.waitKey(0)# & 0xFF

        if chr == ord('1'):
            ui_selected_idx = 0
        if chr == ord('2'):
            ui_selected_idx = 1
        if chr == ord('3'):
            ui_selected_idx = 2
        if chr == ord('4'):
            ui_selected_idx = 3
        if chr == ord('r'):
            print("RRRR")
            
        if chr == ord('q'):
            exit(1)
        if chr == ord('y'):
            break

        if ui_selected_idx != -1:
            print(ui_selected_idx)
            if ui_selected_idx == 0:
                u_idx = 0
                v_idx = 0
            if ui_selected_idx == 1:
                u_idx = -1
                v_idx = 0
            if ui_selected_idx == 2:
                u_idx = 0
                v_idx = -1
            if ui_selected_idx == 3:
                u_idx = -1
                v_idx = -1
            if chr == ord('w'):
                sc[v_idx,u_idx][1] -= 0.001
            if chr == ord('a'):
                sc[v_idx,u_idx][0] -= 0.001
            if chr == ord('s'):
                sc[v_idx,u_idx][1] += 0.001
            if chr == ord('d'):
                sc[v_idx,u_idx][0] += 0.001
            if chr == ord('i'):
                sc[v_idx,u_idx][1] -= 0.1
            if chr == ord('j'):
                sc[v_idx,u_idx][0] -= 0.1
            if chr == ord('k'):
                sc[v_idx,u_idx][1] += 0.1
            if chr == ord('l'):
                sc[v_idx,u_idx][0] += 0.1

    print(sc)
    target_sc = np.zeros((2,2,2))
    target_sc[0,0] = [sc[0,0][0] * original_img.shape[1],sc[0,0][1] * original_img.shape[0]]
    target_sc[0,-1] = [sc[0,-1][0] * original_img.shape[1],sc[0,-1][1] * original_img.shape[0]]
    target_sc[-1,0] = [sc[-1,0][0] * original_img.shape[1],sc[-1,0][1] * original_img.shape[0]]
    target_sc[-1,-1] = [sc[-1,-1][0] * original_img.shape[1],sc[-1,-1][1] * original_img.shape[0]]
    print(target_sc)

    R, T, output = calibrateWindow(cam.intrinsic, cam.distortion, target_sc)
    print("output : ", np.transpose(output))
    print("target_sc : ", target_sc)

    rt = calipy.Transform()
    rt.setParam(R,T)
    rt.saveJson("Gopro_pos.json")
    cv2.destroyAllWindows()
예제 #4
0
import numpy as np
import cv2
import sys
sys.path.append("../")
import calipy
import copy

target_img_path = "./Cameradata/display.png"
cam_param_path = "./Cameradata/Back/cam_intrinsic.json"

output_path = "./Cameradata/TVRT.json"

img = calipy.lib.imreadKorean(target_img_path)
cam_param = calipy.ColorCamera(cam_param_path)
img = cam_param.solveDistortion(img)

offset = 300
uv_points = np.array([ [offset,offset], 
                       [img.shape[1] - offset, offset], 
                       [offset, img.shape[0] - offset], 
                       [img.shape[1] - offset, img.shape[0] - offset] ] )

uv_points = np.array([ [656, 351], 
                       [1085, 380], 
                       [645, 594], 
                       [1075, 620] ] )


def drawImage(img, uv_points, current_idx):
    temp_img = copy.deepcopy(img)
    cv2.line( temp_img, (int(uv_points[0, 0]), int(uv_points[0, 1])), (int(uv_points[1, 0]), int(uv_points[1, 1])), (255,0,0) )
예제 #5
0
    if ret == True:
        corners2 = cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1),
                                    criteria)
        # Draw and display the corners
        img = cv2.drawChessboardCorners(img, (3, 4), corners2, ret)
        cv2.imshow('img', img)

        ch = cv2.waitKey(0)
        if ch == ord('q'):
            exit()
        elif ch == ord('e'):
            break
        elif ch == ord(' '):
            print(fname, " -> Add")
            objpoints.append(objp)
            imgpoints.append(corners2)
        else:
            print(fname, " -> Skip!!!")

ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints,
                                                   gray.shape[::-1], None,
                                                   None)

print(ret)
print(mtx)
print(dist)

camera = calipy.ColorCamera()
camera.setParamFromMatrix(mtx, dist, 1920, 1080)
camera.saveJson(output_path)
예제 #6
0
import calipy
import cv2

cam = calipy.ColorCamera("cam_param.json")
img = cv2.imread("1.png")
img = cam.solveDistortion(img)
cv2.imshow("test", img)
cv2.waitKey(0)