-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
- chessboard image (for calibration)
- chessboard image code
# 저장 폴더 이름
save_dir = "calib_images"
os.makedirs(save_dir, exist_ok=True)
# RealSense는 보통 0번이 아닐 수 있음. 확인 후 번호 수정
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print(" 카메라를 열 수 없습니다.")
exit()
print(" 스페이스바 → 이미지 저장 / ESC → 종료")
img_count = 0
while True:
ret, frame = cap.read()
if not ret:
break
# 화면에 실시간 프레임 출력
cv2.imshow('Press SPACE to save image', frame)
key = cv2.waitKey(1)
# 스페이스바: 이미지 저장
if key == 32:
filename = os.path.join(save_dir, f"chess_{img_count:02d}.jpg")
cv2.imwrite(filename, frame)
print(f" 저장됨: {filename}")
img_count += 1
# ESC 키: 종료
elif key == 27:
break
cap.release()
cv2.destroyAllWindows()
- calibration code
import cv2 as cv
import glob
import os
# 체스보드 내부 코너 수 (가로 x 세로)
chessboard_size = (9, 6)
# 각 칸의 실제 크기 (mm 단위, 예: 25mm = 2.5cm)
square_size = 25
# termination criteria
criteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER, 30, 0.001)
# 체스보드의 3D 좌표계 정의
objp = np.zeros((np.prod(chessboard_size), 3), np.float32)
objp[:, :2] = np.indices(chessboard_size).T.reshape(-1, 2)
objp *= square_size
objpoints = []
imgpoints = []
# 이미지 경로 설정
image_dir = "calib_images"
images = glob.glob(os.path.join(image_dir, "*.jpg"))
print(f" 이미지 {len(images)}장 찾음")
for fname in images:
img = cv.imread(fname)
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
ret, corners = cv.findChessboardCorners(gray, chessboard_size, None)
if ret:
objpoints.append(objp)
corners2 = cv.cornerSubPix(gray, corners, (11,11), (-1,-1), criteria)
imgpoints.append(corners2)
# 코너 그리기 (확인용)
cv.drawChessboardCorners(img, chessboard_size, corners2, ret)
cv.imshow('Corners', img)
cv.waitKey(300)
cv.destroyAllWindows()
# 캘리브레이션 실행
ret, K, dist, rvecs, tvecs = cv.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)
print("\n 카메라 매트릭스 (K):\n", K)
print("\n 왜곡 계수 (dist):\n", dist)
# 결과 저장
np.savez("cam_intrinsics.npz", K=K, dist=dist)
print("\n 캘리브레이션 완료: cam_intrinsics.npz 파일 저장됨")
- rescue point, Aruco Marker, vertiport code image capture
import cv2
import os
# 저장 폴더 이름
save_dir = "calib_images"
os.makedirs(save_dir, exist_ok=True)
# RealSense는 보통 0번이 아닐 수 있음. 확인 후 번호 수정
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("카메라를 열 수 없습니다.")
exit()
print(" 스페이스바 → 이미지 저장 / ESC → 종료")
img_count = 0
while True:
ret, frame = cap.read()
if not ret:
break
# 화면에 실시간 프레임 출력
cv2.imshow('Press SPACE to save image', frame)
key = cv2.waitKey(1)
# 스페이스바: 이미지 저장
if key == 32:
filename = os.path.join(save_dir, f"chess_{img_count:02d}.jpg")
cv2.imwrite(filename, frame)
print(f" 저장됨: {filename}")
img_count += 1
# ESC 키: 종료
elif key == 27:
break
cap.release()
cv2.destroyAllWindows()
- data labelling
https://roboflow.com/
Metadata
Metadata
Assignees
Labels
No labels