Fixing broken calibrate_intrinsics. Write files to json
Changing existing files to .json name
Change-Id: I24c9023700939f8736442d0a61390e4e92a74da5
diff --git a/y2020/vision/tools/python_code/BUILD b/y2020/vision/tools/python_code/BUILD
index 1892a88..a55cb23 100644
--- a/y2020/vision/tools/python_code/BUILD
+++ b/y2020/vision/tools/python_code/BUILD
@@ -12,7 +12,7 @@
args = [
"sift_training_data.h",
],
- data = glob(["calib_files/*.txt"]) + glob([
+ data = glob(["calib_files/*.json"]) + glob([
"test_images/*.png",
]),
default_python_version = "PY3",
@@ -60,7 +60,7 @@
"sift_training_data_test.h",
"test",
],
- data = glob(["calib_files/*.txt"]) + glob([
+ data = glob(["calib_files/*.json"]) + glob([
"test_images/*.png",
]),
default_python_version = "PY3",
diff --git a/y2020/vision/tools/python_code/calib_files/cam-calib-int_pi-7971-3_Feb-13-2020-00-00-00.txt b/y2020/vision/tools/python_code/calib_files/cam-calib-int_pi-7971-3_Feb-13-2020-00-00-00.json
similarity index 100%
rename from y2020/vision/tools/python_code/calib_files/cam-calib-int_pi-7971-3_Feb-13-2020-00-00-00.txt
rename to y2020/vision/tools/python_code/calib_files/cam-calib-int_pi-7971-3_Feb-13-2020-00-00-00.json
diff --git a/y2020/vision/tools/python_code/calib_files/cam-calib-int_pi-971-1_2020-03-07-15-34-00.txt b/y2020/vision/tools/python_code/calib_files/cam-calib-int_pi-971-1_2020-03-07-15-34-00.json
similarity index 100%
rename from y2020/vision/tools/python_code/calib_files/cam-calib-int_pi-971-1_2020-03-07-15-34-00.txt
rename to y2020/vision/tools/python_code/calib_files/cam-calib-int_pi-971-1_2020-03-07-15-34-00.json
diff --git a/y2020/vision/tools/python_code/calibrate_intrinsics.py b/y2020/vision/tools/python_code/calibrate_intrinsics.py
index 828a9a9..fb95599 100644
--- a/y2020/vision/tools/python_code/calibrate_intrinsics.py
+++ b/y2020/vision/tools/python_code/calibrate_intrinsics.py
@@ -1,7 +1,6 @@
import cv2
import cv2.aruco
import datetime
-import glog
import json
from json import JSONEncoder
import numpy as np
@@ -23,9 +22,10 @@
def get_robot_info(hostname):
- hostname_split = hostname[1].split("-")
+ hostname_split = hostname.split("-")
if hostname_split[0] != "pi":
- print("ERROR: expected hostname to start with pi!")
+ print(
+ "ERROR: expected hostname to start with pi! Got '%s'" % hostname)
quit()
team_number = int(hostname_split[1])
@@ -33,11 +33,10 @@
return node_name, team_number
-USE_LARGE_BOARD = False
+USE_LARGE_BOARD = True
if USE_LARGE_BOARD:
dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_5X5_100)
- # Need to measure what the second size parameter is (markerLength)
board = cv2.aruco.CharucoBoard_create(12, 9, .06, .045, dictionary)
img = board.draw((200 * 12, 200 * 9))
else:
@@ -46,7 +45,7 @@
img = board.draw((200 * 11, 200 * 8))
#Dump the calibration board to a file
-cv2.imwrite('charuco.png', img)
+#cv2.imwrite('charuco.png', img)
#Start capturing images for calibration
CAMERA_INDEX = 0 # Capture from /dev/videoX, where X=CAMERA_INDEX
@@ -75,7 +74,7 @@
if keystroke & 0xFF == ord('q'):
break
elif keystroke & 0xFF == ord('c'):
- glog.info("Asked to capture image")
+ print("Asked to capture image")
if len(res[0]) == 0 or len(res[1]) == 0:
# Can't use this image
continue
@@ -86,7 +85,7 @@
charuco_detect_image = frame.copy()
allCorners.append(res2[1])
allIds.append(res2[2])
- glog.info("Capturing image #%d" % capture_count)
+ print("Capturing image #%d" % capture_count)
cv2.aruco.drawDetectedCornersCharuco(charuco_detect_image, res2[1],
res2[2])
@@ -99,14 +98,14 @@
imsize = gray.shape
cal = cv2.aruco.calibrateCameraCharuco(allCorners, allIds, board, imsize,
None, None)
- glog.info("Calibration is:\n", cal)
- glog.info("Reproduction error:", cal[0])
+ print("Calibration is:\n", cal)
+ print("Reproduction error:", cal[0])
if (cal[0] > 1.0):
- glog.error("REPRODUCTION ERROR NOT GOOD")
- glog.info("Calibration matrix:\n", cal[1])
- glog.info("Distortion Coefficients:\n", cal[2])
+ print("REPRODUCTION ERROR NOT GOOD")
+ print("Calibration matrix:\n", cal[1])
+ print("Distortion Coefficients:\n", cal[2])
except:
- glog.error("Calibration failed")
+ print("Calibration failed")
cap.release()
quit()
@@ -125,7 +124,7 @@
numpyData, cls=NumpyArrayEncoder) # use dump() to write array into file
# Write out the data
-calib_file = open("cam_calib_%s_%s.txt" % (hostname, date_str), "w")
+calib_file = open("cam_calib_%s_%s.json" % (hostname, date_str), "w")
calib_file.write(encodedNumpyData)
calib_file.close()
diff --git a/y2020/vision/tools/python_code/camera_definition.py b/y2020/vision/tools/python_code/camera_definition.py
index 578c9cc..da20a52 100644
--- a/y2020/vision/tools/python_code/camera_definition.py
+++ b/y2020/vision/tools/python_code/camera_definition.py
@@ -81,7 +81,7 @@
dir_name = dtd.bazel_name_fix('calib_files')
for filename in os.listdir(dir_name):
- if "cam-calib-int" in filename and filename.endswith(".txt"):
+ if "cam-calib-int" in filename and filename.endswith(".json"):
# Extract intrinsics from file
fn_split = filename.split("_")
hostname_split = fn_split[1].split("-")