From d8e194755dd39d226006f004f91c823cb31d4da3 Mon Sep 17 00:00:00 2001 From: JoshWu Date: Tue, 5 Jan 2021 12:45:47 +0800 Subject: [PATCH 1/4] run_calibrate_camera: add an option '--no_gst' to disable gstreamer If specified '--no_gst', then the camera device just be used by opencv without any gstreamer components. Signed-off-by: JoshWu --- run_calibrate_camera.py | 7 ++++++- surround_view/capture_thread.py | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/run_calibrate_camera.py b/run_calibrate_camera.py index a88c52c..04c71d0 100644 --- a/run_calibrate_camera.py +++ b/run_calibrate_camera.py @@ -50,6 +50,9 @@ def main(): parser.add_argument("-flip", "--flip", default=0, type=int, help="flip method of the camera") + parser.add_argument("--no_gst", action="store_true", + help="set true if not use gstreamer for the camera capture") + args = parser.parse_args() if not os.path.exists(TARGET_DIR): @@ -70,7 +73,9 @@ def main(): device = args.input cap_thread = CaptureThread(device_id=device, - flip_method=args.flip) + flip_method=args.flip, + use_gst=not args.no_gst, + ) buffer_manager = MultiBufferManager() buffer_manager.bind_thread(cap_thread, buffer_size=8) if cap_thread.connect_camera(): diff --git a/surround_view/capture_thread.py b/surround_view/capture_thread.py index cfe73ae..1589999 100644 --- a/surround_view/capture_thread.py +++ b/surround_view/capture_thread.py @@ -14,6 +14,7 @@ def __init__(self, drop_if_full=True, api_preference=cv2.CAP_GSTREAMER, resolution=None, + use_gst=True, parent=None): """ device_id: device number of the camera. @@ -26,6 +27,7 @@ def __init__(self, super(CaptureThread, self).__init__(parent) self.device_id = device_id self.flip_method = flip_method + self.use_gst = use_gst self.drop_if_full = drop_if_full self.api_preference = api_preference self.resolution = resolution @@ -71,8 +73,11 @@ def run(self): qDebug("Stopping capture thread...") def connect_camera(self): - options = gstreamer_pipeline(cam_id=self.device_id, flip_method=self.flip_method) - self.cap.open(options, self.api_preference) + if self.use_gst: + options = gstreamer_pipeline(cam_id=self.device_id, flip_method=self.flip_method) + self.cap.open(options, self.api_preference) + else: + self.cap.open(self.device_id) # return false if failed to open camera if not self.cap.isOpened(): qDebug("Cannot open camera {}".format(self.device_id)) From 1f5a62b462e58149579b32ce4685ddc586e9a255 Mon Sep 17 00:00:00 2001 From: JoshWu Date: Tue, 5 Jan 2021 12:51:21 +0800 Subject: [PATCH 2/4] run_calibrate_camera: support '--resolution' or '-r' option Signed-off-by: JoshWu --- run_calibrate_camera.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/run_calibrate_camera.py b/run_calibrate_camera.py index 04c71d0..a905176 100644 --- a/run_calibrate_camera.py +++ b/run_calibrate_camera.py @@ -9,7 +9,7 @@ -grid 9x6 \ -out fisheye.yaml \ -framestep 20 \ - -resolution 640x480 + --resolution 640x480 --fisheye """ import argparse @@ -38,6 +38,9 @@ def main(): parser.add_argument("-grid", "--grid", default="9x6", help="size of the calibrate grid pattern") + parser.add_argument("-r", "--resolution", default="640x480", + help="resolution of the camera image") + parser.add_argument("-framestep", type=int, default=20, help="use every nth frame in the video") @@ -64,6 +67,9 @@ def main(): font = cv2.FONT_HERSHEY_SIMPLEX fontscale = 0.6 + resolution_str = args.resolution.split("x") + W = int(resolution_str[0]) + H = int(resolution_str[1]) grid_size = tuple(int(x) for x in args.grid.split("x")) grid_points = np.zeros((1, np.prod(grid_size), 3), np.float32) grid_points[0, :, :2] = np.indices(grid_size).T.reshape(-1, 2) @@ -74,6 +80,7 @@ def main(): device = args.input cap_thread = CaptureThread(device_id=device, flip_method=args.flip, + resolution=(W, H), use_gst=not args.no_gst, ) buffer_manager = MultiBufferManager() From 3ef08c16c70d162ed610dcc91276304751e7fbed Mon Sep 17 00:00:00 2001 From: JoshWu Date: Tue, 5 Jan 2021 12:54:11 +0800 Subject: [PATCH 3/4] run_calibrate_camera: won't quit the application if failed to calibrate Make the calibration process is more user-friendly. Signed-off-by: JoshWu --- run_calibrate_camera.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/run_calibrate_camera.py b/run_calibrate_camera.py index a905176..0a4851f 100644 --- a/run_calibrate_camera.py +++ b/run_calibrate_camera.py @@ -123,8 +123,14 @@ def main(): cv2.imshow("corners", img) key = cv2.waitKey(1) & 0xFF if key == ord("c"): - do_calib = True - break + print("\nPerforming calibration...\n") + N_OK = len(objpoints) + if N_OK < 12: + print("Less than 12 corners (%d) detected, calibration failed" %(N_OK)) + continue + else: + do_calib = True + break elif key == ord("q"): quit = True @@ -136,12 +142,7 @@ def main(): cv2.destroyAllWindows() if do_calib: - print("\nPerforming calibration...\n") N_OK = len(objpoints) - if N_OK < 12: - print("Less than 12 corners detected, calibration failed") - return - K = np.zeros((3, 3)) D = np.zeros((4, 1)) rvecs = [np.zeros((1, 1, 3), dtype=np.float64) for _ in range(N_OK)] From f08d5a7fa1aa57b87cbe3286eec05a57b5782e3c Mon Sep 17 00:00:00 2001 From: JoshWu Date: Tue, 5 Jan 2021 13:01:42 +0800 Subject: [PATCH 4/4] trivial: add more comments for simple_gui.py code Signed-off-by: JoshWu --- surround_view/simple_gui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/surround_view/simple_gui.py b/surround_view/simple_gui.py index 82641ab..3327f03 100644 --- a/surround_view/simple_gui.py +++ b/surround_view/simple_gui.py @@ -1,7 +1,7 @@ import cv2 import numpy as np - +# return -1 if user press 'q'. return 1 if user press 'Enter'. def display_image(window_title, image): cv2.imshow(window_title, image) while True: @@ -13,6 +13,7 @@ def display_image(window_title, image): if key == ord("q"): return -1 + # 'Enter' key is detected! if key == 13: return 1