Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cameras other that PS3 Eye #8

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions calibtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ def save_calib():
def get_cam(type, id):
if type == "PS3 Eye Camera":
return camera.Camera(id, (640, 480), 50, camera.ps3eye_format.PS3EYE_FORMAT_BGR)
else:
return cv2.VideoCapture(id+700) #open camera at id with the directshow API (700). Note that same camera is not always on the same id, so this needs a better way.

def add_camera():
ids = list(range(camera.get_camera_count()))

add_camera_layout = [
[sg.Text('Add Camera', font="SegoeUI 16", justification='center')],
[sg.Text('Camera Type:', font="SegoeUI 12"), sg.Combo(values=["PS3 Eye Camera"], key="camtype", readonly=True, default_value="PS3 Eye Camera")],
[sg.Text('Camera ID:', font="SegoeUI 12"), sg.Combo(values=ids, key="camid", readonly=True, default_value=ids[0])],
[sg.Text('Camera Type:', font="SegoeUI 12"), sg.Combo(values=["PS3 Eye Camera", "other"], key="camtype", readonly=True, default_value="PS3 Eye Camera")],
[sg.Text('Camera ID:', font="SegoeUI 12"), sg.Combo(values=[0,1,2,3], key="camid", readonly=True, default_value=ids[0])],
[sg.Text('Name (optional):', font="SegoeUI 12"), sg.Input(key="camname", size=(15, 1))],
[sg.Button('Add', key="add"), sg.Button('Cancel', key="cancel")]
]
Expand Down Expand Up @@ -137,6 +139,7 @@ def calibrate_intrinsics(cam, cap):

ret, frame = cap.read()
if ret:
frame = cv2.rotate(frame,2)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
ret2, corners = cv2.findChessboardCornersSB(gray, (rows, columns), None, cv2.CALIB_CB_EXHAUSTIVE | cv2.CALIB_CB_ACCURACY)
if ret2 == True:
Expand Down Expand Up @@ -222,6 +225,7 @@ def calibrate_extrinsics():
n = math.ceil(math.sqrt(len(cameras)))
for i, cam in enumerate(cameras):
ret, frame = cam.read()
frame = cv2.rotate(frame,2) #rotate camera sideways, as that gives more vertical space. Should be a setting somewhere
if ret:
if "intrinsics" in calib["cameras"][i]:
cmtx, dist, opt_cmtx = np.array(calib["cameras"][i]["intrinsics"]["cmtx"]), np.array(calib["cameras"][i]["intrinsics"]["dist"]), np.array(calib["cameras"][i]["intrinsics"]["opt_cmtx"])
Expand All @@ -236,7 +240,8 @@ def calibrate_extrinsics():
lastseen[i] = 0
else:
lastseen[i] = min(5, lastseen[i] + 0.1)


colors = [np.full(frame.shape, (0, (5-i) * 51, i * 51), dtype=np.uint8) for i in range(6)] #since the image is no longer always 640x480, we change the size to frame.shape
frame = cv2.addWeighted(frame, 1, colors[int(lastseen[i])], 0.1, 0)

if i == 0 and len(corners) > 0:
Expand Down Expand Up @@ -357,13 +362,17 @@ def update_camera_list():
save_calib()

elif event == "extrinsics":
cap.__del__()
#cap.__del__() #this caused a crash. Works okay without?
calibrate_extrinsics()
save_calib()
update_camera_list()

elif cap:
frame = cap.get_frame()

ret, frame = cap.read()
if not ret:
continue
frame = cv2.rotate(frame,2) #rotate camera sideways, as that gives more vertical space. Should be a setting somewhere
if "intrinsics" in cam:
cmtx, dist, opt_cmtx = np.array(cam["intrinsics"]["cmtx"]), np.array(cam["intrinsics"]["dist"]), np.array(cam["intrinsics"]["opt_cmtx"])
frame = cv2.undistort(frame, cmtx, dist, None, opt_cmtx)
Expand Down
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
running = True

#region Camera Initialization
fps = settings.get("fps", 50)
fps = settings.get("fps", 30) #change default fps to 30
res = (640, 480)

cam_count = len(calib["cameras"])
Expand Down Expand Up @@ -62,7 +62,8 @@
# A cam_thread gets spun up for each camera for being able to fetch frames in parallel
def cam_thread(id):
while running:
frame = cameras[id].get_frame()
_, frame = cameras[id].read() #.read() is general for both cv2 and ps eyes
frame = cv2.rotate(frame,2) #rotate camera sideways, as that gives more vertical space. Should be a setting somewhere
if settings.get("undistort", True):
frame = cv2.undistort(frame, oncm[id][0], oncm[id][1], None, oncm[id][2])
frame.flags.writeable = False
Expand Down
2 changes: 2 additions & 0 deletions utils/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
def get_cam(type, id):
if type == "PS3 Eye Camera":
return camera.Camera(id, (640, 480), 50, camera.ps3eye_format.PS3EYE_FORMAT_BGR)
else:
return cv2.VideoCapture(id+700) #open camera at id with the directshow API (700). Note that same camera is not always on the same id, so this needs a better way.

def _make_homogeneous_rep_matrix(R, t):
P = np.zeros((4,4))
Expand Down