├── .gitattributes ├── wide.jpg ├── normal.jpg ├── pattern.png ├── pairs ├── .DS_Store ├── left_01.png ├── left_02.png ├── left_03.png ├── left_04.png ├── left_05.png ├── left_06.png ├── left_07.png ├── left_08.png ├── left_09.png ├── left_10.png ├── left_11.png ├── left_12.png ├── left_13.png ├── left_14.png ├── left_15.png ├── left_16.png ├── left_17.png ├── left_18.png ├── left_19.png ├── left_20.png ├── left_21.png ├── left_22.png ├── left_24.png ├── left_25.png ├── left_26.png ├── left_27.png ├── left_28.png ├── left_29.png ├── left_30.png ├── left_31.png ├── left_32.png ├── left_33.png ├── left_34.png ├── left_35.png ├── left_36.png ├── left_37.png ├── left_38.png ├── left_39.png ├── left_40.png ├── left_41.png ├── left_42.png ├── left_43.png ├── left_44.png ├── left_45.png ├── left_46.png ├── left_47.png ├── left_48.png ├── left_49.png ├── left_50.png ├── right_01.png ├── right_02.png ├── right_03.png ├── right_04.png ├── right_05.png ├── right_06.png ├── right_07.png ├── right_08.png ├── right_09.png ├── right_10.png ├── right_11.png ├── right_12.png ├── right_13.png ├── right_14.png ├── right_15.png ├── right_16.png ├── right_17.png ├── right_18.png ├── right_19.png ├── right_20.png ├── right_21.png ├── right_22.png ├── right_23.png ├── right_24.png ├── right_25.png ├── right_26.png ├── right_27.png ├── right_28.png ├── right_29.png ├── right_30.png ├── right_31.png ├── right_32.png ├── right_33.png ├── right_34.png ├── right_35.png ├── right_36.png ├── right_37.png ├── right_38.png ├── right_39.png ├── right_40.png ├── right_41.png ├── right_42.png ├── right_43.png ├── right_44.png ├── right_45.png ├── right_46.png ├── right_47.png ├── right_48.png ├── right_49.png └── right_50.png ├── scenes ├── photo.png ├── dm-tune.jpg ├── dm-tune-example.jpg ├── scene_1280x480_1.png ├── scene_1280x480_2.png ├── scene_1280x480_3.png ├── scene_1280x480_4.png ├── scene_1280x480_5.png ├── scene_1280x480_6.png ├── scene_1280x480_7.png ├── scene_1280x480_8.png ├── scene_1280x480_9.png ├── scene_1280x480_10.png ├── scene_1280x480_11.png ├── scene_1280x480_12.png ├── scene_1280x480_13.png ├── scene_1280x480_14.png ├── scene_1280x480_15.png ├── scene_1280x480_16.png ├── scene_1280x480_17.png ├── scene_1280x480_18.png ├── scene_1280x480_19.png ├── scene_1280x480_20.png ├── scene_1280x480_21.png ├── scene_1280x480_22.png ├── scene_1280x480_23.png ├── scene_1280x480_24.png ├── scene_1280x480_25.png ├── scene_1280x480_26.png ├── scene_1280x480_27.png ├── scene_1280x480_28.png ├── scene_1280x480_29.png ├── scene_1280x480_30.png ├── scene_1280x480_31.png ├── scene_1280x480_32.png ├── scene_1280x480_33.png ├── scene_1280x480_34.png ├── scene_1280x480_35.png ├── scene_1280x480_36.png ├── scene_1280x480_37.png ├── scene_1280x480_38.png ├── scene_1280x480_39.png ├── scene_1280x480_40.png ├── scene_1280x480_41.png ├── scene_1280x480_42.png ├── scene_1280x480_43.png ├── scene_1280x480_44.png ├── scene_1280x480_45.png ├── scene_1280x480_46.png ├── scene_1280x480_47.png ├── scene_1280x480_48.png ├── scene_1280x480_49.png └── scene_1280x480_50.png ├── rectifyed_left.jpg ├── rectifyed_right.jpg ├── undistorted_left.jpg ├── undistorted_right.jpg ├── calibration_data ├── .DS_Store └── 240p │ ├── camera_calibration_left.npz │ ├── camera_calibration_right.npz │ └── stereo_camera_calibration.npz ├── 3dmap_set.txt ├── README.md ├── 3_pairs_cut.py ├── 1_test.py ├── buster-opencv-notice.md ├── 2_chess_cycle.py ├── 6_dm_video.py ├── 7_2d_map.py ├── 5_dm_tune.py ├── 4_calibration_fisheye.py └── LICENSE /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /wide.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/wide.jpg -------------------------------------------------------------------------------- /normal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/normal.jpg -------------------------------------------------------------------------------- /pattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pattern.png -------------------------------------------------------------------------------- /pairs/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/.DS_Store -------------------------------------------------------------------------------- /pairs/left_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_01.png -------------------------------------------------------------------------------- /pairs/left_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_02.png -------------------------------------------------------------------------------- /pairs/left_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_03.png -------------------------------------------------------------------------------- /pairs/left_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_04.png -------------------------------------------------------------------------------- /pairs/left_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_05.png -------------------------------------------------------------------------------- /pairs/left_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_06.png -------------------------------------------------------------------------------- /pairs/left_07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_07.png -------------------------------------------------------------------------------- /pairs/left_08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_08.png -------------------------------------------------------------------------------- /pairs/left_09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_09.png -------------------------------------------------------------------------------- /pairs/left_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_10.png -------------------------------------------------------------------------------- /pairs/left_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_11.png -------------------------------------------------------------------------------- /pairs/left_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_12.png -------------------------------------------------------------------------------- /pairs/left_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_13.png -------------------------------------------------------------------------------- /pairs/left_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_14.png -------------------------------------------------------------------------------- /pairs/left_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_15.png -------------------------------------------------------------------------------- /pairs/left_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_16.png -------------------------------------------------------------------------------- /pairs/left_17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_17.png -------------------------------------------------------------------------------- /pairs/left_18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_18.png -------------------------------------------------------------------------------- /pairs/left_19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_19.png -------------------------------------------------------------------------------- /pairs/left_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_20.png -------------------------------------------------------------------------------- /pairs/left_21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_21.png -------------------------------------------------------------------------------- /pairs/left_22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_22.png -------------------------------------------------------------------------------- /pairs/left_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_24.png -------------------------------------------------------------------------------- /pairs/left_25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_25.png -------------------------------------------------------------------------------- /pairs/left_26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_26.png -------------------------------------------------------------------------------- /pairs/left_27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_27.png -------------------------------------------------------------------------------- /pairs/left_28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_28.png -------------------------------------------------------------------------------- /pairs/left_29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_29.png -------------------------------------------------------------------------------- /pairs/left_30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_30.png -------------------------------------------------------------------------------- /pairs/left_31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_31.png -------------------------------------------------------------------------------- /pairs/left_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_32.png -------------------------------------------------------------------------------- /pairs/left_33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_33.png -------------------------------------------------------------------------------- /pairs/left_34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_34.png -------------------------------------------------------------------------------- /pairs/left_35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_35.png -------------------------------------------------------------------------------- /pairs/left_36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_36.png -------------------------------------------------------------------------------- /pairs/left_37.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_37.png -------------------------------------------------------------------------------- /pairs/left_38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_38.png -------------------------------------------------------------------------------- /pairs/left_39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_39.png -------------------------------------------------------------------------------- /pairs/left_40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_40.png -------------------------------------------------------------------------------- /pairs/left_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_41.png -------------------------------------------------------------------------------- /pairs/left_42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_42.png -------------------------------------------------------------------------------- /pairs/left_43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_43.png -------------------------------------------------------------------------------- /pairs/left_44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_44.png -------------------------------------------------------------------------------- /pairs/left_45.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_45.png -------------------------------------------------------------------------------- /pairs/left_46.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_46.png -------------------------------------------------------------------------------- /pairs/left_47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_47.png -------------------------------------------------------------------------------- /pairs/left_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_48.png -------------------------------------------------------------------------------- /pairs/left_49.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_49.png -------------------------------------------------------------------------------- /pairs/left_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/left_50.png -------------------------------------------------------------------------------- /scenes/photo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/photo.png -------------------------------------------------------------------------------- /pairs/right_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_01.png -------------------------------------------------------------------------------- /pairs/right_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_02.png -------------------------------------------------------------------------------- /pairs/right_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_03.png -------------------------------------------------------------------------------- /pairs/right_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_04.png -------------------------------------------------------------------------------- /pairs/right_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_05.png -------------------------------------------------------------------------------- /pairs/right_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_06.png -------------------------------------------------------------------------------- /pairs/right_07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_07.png -------------------------------------------------------------------------------- /pairs/right_08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_08.png -------------------------------------------------------------------------------- /pairs/right_09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_09.png -------------------------------------------------------------------------------- /pairs/right_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_10.png -------------------------------------------------------------------------------- /pairs/right_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_11.png -------------------------------------------------------------------------------- /pairs/right_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_12.png -------------------------------------------------------------------------------- /pairs/right_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_13.png -------------------------------------------------------------------------------- /pairs/right_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_14.png -------------------------------------------------------------------------------- /pairs/right_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_15.png -------------------------------------------------------------------------------- /pairs/right_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_16.png -------------------------------------------------------------------------------- /pairs/right_17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_17.png -------------------------------------------------------------------------------- /pairs/right_18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_18.png -------------------------------------------------------------------------------- /pairs/right_19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_19.png -------------------------------------------------------------------------------- /pairs/right_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_20.png -------------------------------------------------------------------------------- /pairs/right_21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_21.png -------------------------------------------------------------------------------- /pairs/right_22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_22.png -------------------------------------------------------------------------------- /pairs/right_23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_23.png -------------------------------------------------------------------------------- /pairs/right_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_24.png -------------------------------------------------------------------------------- /pairs/right_25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_25.png -------------------------------------------------------------------------------- /pairs/right_26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_26.png -------------------------------------------------------------------------------- /pairs/right_27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_27.png -------------------------------------------------------------------------------- /pairs/right_28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_28.png -------------------------------------------------------------------------------- /pairs/right_29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_29.png -------------------------------------------------------------------------------- /pairs/right_30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_30.png -------------------------------------------------------------------------------- /pairs/right_31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_31.png -------------------------------------------------------------------------------- /pairs/right_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_32.png -------------------------------------------------------------------------------- /pairs/right_33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_33.png -------------------------------------------------------------------------------- /pairs/right_34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_34.png -------------------------------------------------------------------------------- /pairs/right_35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_35.png -------------------------------------------------------------------------------- /pairs/right_36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_36.png -------------------------------------------------------------------------------- /pairs/right_37.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_37.png -------------------------------------------------------------------------------- /pairs/right_38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_38.png -------------------------------------------------------------------------------- /pairs/right_39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_39.png -------------------------------------------------------------------------------- /pairs/right_40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_40.png -------------------------------------------------------------------------------- /pairs/right_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_41.png -------------------------------------------------------------------------------- /pairs/right_42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_42.png -------------------------------------------------------------------------------- /pairs/right_43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_43.png -------------------------------------------------------------------------------- /pairs/right_44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_44.png -------------------------------------------------------------------------------- /pairs/right_45.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_45.png -------------------------------------------------------------------------------- /pairs/right_46.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_46.png -------------------------------------------------------------------------------- /pairs/right_47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_47.png -------------------------------------------------------------------------------- /pairs/right_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_48.png -------------------------------------------------------------------------------- /pairs/right_49.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_49.png -------------------------------------------------------------------------------- /pairs/right_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/pairs/right_50.png -------------------------------------------------------------------------------- /rectifyed_left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/rectifyed_left.jpg -------------------------------------------------------------------------------- /rectifyed_right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/rectifyed_right.jpg -------------------------------------------------------------------------------- /scenes/dm-tune.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/dm-tune.jpg -------------------------------------------------------------------------------- /undistorted_left.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/undistorted_left.jpg -------------------------------------------------------------------------------- /undistorted_right.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/undistorted_right.jpg -------------------------------------------------------------------------------- /calibration_data/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/calibration_data/.DS_Store -------------------------------------------------------------------------------- /scenes/dm-tune-example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/dm-tune-example.jpg -------------------------------------------------------------------------------- /scenes/scene_1280x480_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_1.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_2.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_3.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_4.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_5.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_6.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_7.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_8.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_9.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_10.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_11.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_12.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_13.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_14.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_15.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_16.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_17.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_18.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_19.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_20.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_21.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_22.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_23.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_24.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_25.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_26.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_27.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_28.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_29.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_30.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_31.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_32.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_33.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_34.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_35.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_36.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_37.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_37.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_38.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_39.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_40.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_41.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_42.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_43.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_44.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_45.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_45.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_46.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_46.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_47.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_48.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_49.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_49.png -------------------------------------------------------------------------------- /scenes/scene_1280x480_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/scenes/scene_1280x480_50.png -------------------------------------------------------------------------------- /calibration_data/240p/camera_calibration_left.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/calibration_data/240p/camera_calibration_left.npz -------------------------------------------------------------------------------- /calibration_data/240p/camera_calibration_right.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/calibration_data/240p/camera_calibration_right.npz -------------------------------------------------------------------------------- /calibration_data/240p/stereo_camera_calibration.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/realizator/stereopi-fisheye-robot/HEAD/calibration_data/240p/stereo_camera_calibration.npz -------------------------------------------------------------------------------- /3dmap_set.txt: -------------------------------------------------------------------------------- 1 | { 2 | "SADWindowSize":7, 3 | "minDisparity":42, 4 | "numberOfDisparities":16, 5 | "preFilterCap":29, 6 | "preFilterSize":7, 7 | "speckleRange":0, 8 | "speckleWindowSize":2, 9 | "textureThreshold":31, 10 | "uniquenessRatio":9 11 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | StereoPi fisheye robot tutorial scripts 2 | =========== 3 | 4 | Set of StereoPi Fisheye Robot tutorial scripts for StereoPi board with CM3/3+ inside. 5 | 6 | Was tested in the following environment: 7 | * Raspbian Buster (kernel 4.19.57-v7+) 8 | * Python 3.7.3 9 | * OpenCV 3.4.3 or 4.1.0.25 (pre-compiled, 'pip' from Python Wheels) 10 | * Picamera 1.13 11 | 12 | Related article: https://medium.com/stereopi/a-robot-on-stereopi-part-1-fisheye-cameras-92aa56e73a94 13 | Related 2nd article: https://stereopi.com/blog/opencv-comparing-speed-c-and-python-code-raspberry-pi-stereo-vision 14 | 15 | ### Updated Buster image (Python and C++ code) 4.7 Gb, for a 16 Gb eMMC or micro SD card: 16 | 17 | [Google drive](https://drive.google.com/file/d/1xlkvZMl9gJGm4Gy1oVlGknHywDnvy5gS/view?usp=sharing) 18 | 19 | ### Buster Raspbian OpenCV image, OCT 2024 (Python code only, 2.28Gb, needs 8Gb micro SD or eMMC): 20 | 21 | [MediaFire](https://www.mediafire.com/folder/nzr90vj8wp1l3/StereoPi_Images) 22 | 23 | 24 | ### Want to prepare OpenCV Raspbian Buster image by yourself? 25 | 26 | Follow this guide: [buster-opencv-notice.md](https://github.com/realizator/stereopi-fisheye-robot/blob/master/buster-opencv-notice.md) 27 | 28 | If you did Raspbian update, and stereoscopic capture command (like 'raspistill -3d sbs') hangs your StereoPi - please do 'sudo rpi-update' to fix it. 29 | 30 | ### Brief scripts description: 31 | 32 | **1_test.py** - starts camera preview, save captured image if 'Q' button is pressed. 33 | align. 34 | 35 | **2_chess_cycle.py** - takes a series of photos for stereopair calibration, shows count 36 | down timer. You need a printed chessboard with 9x6 parameters (file "pattern.png" included). 37 | 38 | **3_pairs_cut.py** - just cuts all captured photos to left and right images. 39 | 40 | **4_calibration_fisheye.py** - calibrate StereoPi cameas setup using pairs from script 4. 41 | 42 | **5_dm_tune.py** - script for fine tune of disparity map settings. 43 | 44 | **6_dm_video.py** - builds disparity map in real time. 45 | 46 | 47 | **7_2d_map.py** - builds 2D map from the depth map. 48 | 49 | 50 | -------------------------------------------------------------------------------- /3_pairs_cut.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Eugene a.k.a. Realizator, stereopi.com, virt2real team 2 | # 3 | # This file is part of StereoPi tutorial scripts. 4 | # 5 | # StereoPi tutorial is free software: you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License 7 | # as published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # StereoPi tutorial is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with StereoPi tutorial. 17 | # If not, see . 18 | # 19 | # <><><> SPECIAL THANKS: <><><> 20 | # 21 | # Thanks to Adrian and http://pyimagesearch.com, as a lot of 22 | # code in this tutorial was taken from his lessons. 23 | # 24 | # Thanks to RPi-tankbot project: https://github.com/Kheiden/RPi-tankbot 25 | # 26 | # Thanks to rakali project: https://github.com/sthysel/rakali 27 | 28 | 29 | import cv2 30 | import os 31 | 32 | # Global variables preset 33 | total_photos = 50 34 | 35 | # Photos to be cutted resolution 36 | photo_width = 1280 37 | photo_height = 480 38 | 39 | # Left and right images resolution 40 | img_width = 640 41 | img_height = 480 42 | 43 | # Visualization options 44 | ShowImages = False 45 | 46 | # Counter setup 47 | photo_counter = 0 48 | 49 | # Main pair cut cycle 50 | if (os.path.isdir("./pairs")==False): 51 | os.makedirs("./pairs") 52 | while photo_counter != total_photos: 53 | photo_counter +=1 54 | filename = './scenes/scene_'+str(photo_width)+'x'+str(photo_height)+\ 55 | '_'+str(photo_counter) + '.png' 56 | if os.path.isfile(filename) == False: 57 | print ("No file named "+filename) 58 | continue 59 | pair_img = cv2.imread(filename,-1) 60 | 61 | if (ShowImages): 62 | cv2.imshow("ImagePair", pair_img) 63 | cv2.waitKey(0) 64 | imgLeft = pair_img [0:img_height,0:img_width] #Y+H and X+W 65 | imgRight = pair_img [0:img_height,img_width:photo_width] 66 | leftName = './pairs/left_'+str(photo_counter).zfill(2)+'.png' 67 | rightName = './pairs/right_'+str(photo_counter).zfill(2)+'.png' 68 | cv2.imwrite(leftName, imgLeft) 69 | cv2.imwrite(rightName, imgRight) 70 | print ('Pair No '+str(photo_counter)+' saved.') 71 | 72 | print ('End cycle') 73 | -------------------------------------------------------------------------------- /1_test.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Eugene a.k.a. Realizator, stereopi.com, virt2real team 2 | # 3 | # This file is part of StereoPi tutorial scripts. 4 | # 5 | # StereoPi tutorial is free software: you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License 7 | # as published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # StereoPi tutorial is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with StereoPi tutorial. 17 | # If not, see . 18 | # 19 | # <><><> SPECIAL THANKS: <><><> 20 | # 21 | # Thanks to Adrian and http://pyimagesearch.com, as a lot of 22 | # code in this tutorial was taken from his lessons. 23 | # 24 | # Thanks to RPi-tankbot project: https://github.com/Kheiden/RPi-tankbot 25 | # 26 | # Thanks to rakali project: https://github.com/sthysel/rakali 27 | 28 | 29 | import picamera 30 | from picamera import PiCamera 31 | import time 32 | import cv2 33 | import numpy as np 34 | import os 35 | from datetime import datetime 36 | 37 | # User quit method message 38 | print("You can press 'Q' to quit this script.") 39 | 40 | # File for captured image 41 | filename = './scenes/photo.png' 42 | 43 | # Camera settimgs 44 | cam_width = 1280 45 | cam_height = 480 46 | 47 | # Final image capture settings 48 | scale_ratio = 0.5 49 | 50 | # Camera resolution height must be dividable by 16, and width by 32 51 | cam_width = int((cam_width+31)/32)*32 52 | cam_height = int((cam_height+15)/16)*16 53 | print ("Camera resolution: "+str(cam_width)+" x "+str(cam_height)) 54 | 55 | # Buffer for captured image settings 56 | img_width = int (cam_width * scale_ratio) 57 | img_height = int (cam_height * scale_ratio) 58 | capture = np.zeros((img_height, img_width, 4), dtype=np.uint8) 59 | print ("Scaled image resolution: "+str(img_width)+" x "+str(img_height)) 60 | 61 | # Initialize the camera 62 | camera = PiCamera(stereo_mode='side-by-side',stereo_decimate=False) 63 | camera.resolution=(cam_width, cam_height) 64 | camera.framerate = 20 65 | #camera.hflip = True 66 | 67 | t0 = datetime.now() 68 | counter = 0 69 | avgtime = 0 70 | # Capture frames from the camera 71 | for frame in camera.capture_continuous(capture, format="bgra", use_video_port=True, resize=(img_width,img_height)): 72 | counter+=1 73 | cv2.imshow("pair", frame) 74 | key = cv2.waitKey(1) & 0xFF 75 | # if the `q` key was pressed, break from the loop and save last image 76 | if key == ord("q") : 77 | t1 = datetime.now() 78 | timediff = t1-t0 79 | print ("Average time between frames: " + str(avgtime)) 80 | print ("Frames: " + str(counter) + " Time: " + str(timediff.total_seconds())+ " Average FPS: " + str(counter/timediff.total_seconds())) 81 | if (os.path.isdir("./scenes")==False): 82 | os.makedirs("./scenes") 83 | cv2.imwrite(filename, frame) 84 | exit(0) 85 | break 86 | 87 | 88 | -------------------------------------------------------------------------------- /buster-opencv-notice.md: -------------------------------------------------------------------------------- 1 | ### Critical notice! 2 | In the latest Raspbian kernels stereoscopic support has been occasionally broken by implementing new AWB algorithm. You can read some details [here](https://github.com/raspberrypi/firmware/issues/1253). Kernels affected: 4.19.57 and up to 4.19.97. Our Raspbian image provided has no such a problem (as it is based on older kernel). 3 | 4 | The solution (**obsolete**): 5 | 6 | after boot run once this command before accessing your cameras: 7 | ``` 8 | sudo vcdbg set awb_mode 0 9 | ``` 10 | This will turn AWB algo to the previous mode, and stereo works again untill next reboot. So run this command after reboot, or add it to your autorun script. 11 | 12 | New solution (**recommended**): 13 | 14 | `sudo rpi-update` 15 | 16 | As of 10 of April, 2020, issue is fixed in the latest firmware update. So just use rpi-update. 17 | 18 | 19 | # Installing OpenCV 3.x or 4.x on Raspbian Buster: 20 | 21 | #### 1. Download Raspbian Buster and write image to your micro SD card. 22 | 23 | 24 | #### 2. Enable two cameras support: 25 | Put [dt-blob.bin](http://wiki.stereopi.com/files/dt-blob.bin.zip) file to /BOOT partition. Do not forget to extract it from ZIP archive. 26 | 27 | #### 3. First boot 28 | 29 | After the first boot you'll see setup wizard. 30 | 31 | Choose all settings you need, install all recommended updates and reboot the StereoPi. 32 | 33 | Please do 'sudo rpi-update' after that. This will fix stereoscopic mode. 34 | 35 | Enable camera: 36 | 37 | `sudo raspi-config` 38 | 39 | Go to "Interfacing options", choose "Enable camera", press "Yes", reboot your system. 40 | 41 | #### 4. Set python 3 as a default: 42 | 43 | `sudo nano ~/.bashrc` 44 | 45 | add this row at the end of file: 46 | 47 | `alias python='/usr/bin/python3'` 48 | 49 | Save the file (Esc X X, "yes"). 50 | 51 | Activate new settings: 52 | 53 | `source ~/.bashrc` 54 | 55 | Check if the settings are applied correctly. 56 | 57 | `python` 58 | 59 | You should see "Python 3.7.3" in the first row. 60 | 61 | If you see "Python 2.7.x" - please repeat previous steps. 62 | 63 | (Type exit(0) to exit Python command line). 64 | 65 | #### 5. Install OpenCV with PiWheels: 66 | 67 | Workaround: to avoid "undefined symbol: __atomic_fetch_add8" error while "import cv2", 68 | please install specific version of OpenCV. 69 | 70 | For OpenCV 3.x use: 71 | 72 | `sudo pip3 install opencv-python==3.4.6.27` 73 | 74 | For OpenCV 4.x use: 75 | 76 | `sudo pip3 install opencv-contrib-python==4.1.0.25` 77 | 78 | #### 6. Install additional libs: 79 | 80 | ``` 81 | sudo apt-get install libhdf5-dev 82 | sudo apt-get install libhdf5-serial-dev 83 | sudo apt-get install libatlas-base-dev 84 | sudo apt-get install libjasper-dev 85 | sudo apt-get install libqtgui4 86 | sudo apt-get install libqt4-test 87 | ``` 88 | 89 | You may also need matplotlib. Go this way: 90 | 91 | `sudo pip3 install matplotlib` 92 | 93 | #### 7. To check if everything Ok try to run our first test script: 94 | 95 | `python 1_test.py` 96 | 97 | You should see preview image. Press 'Q' for exit. 98 | 99 | #### 8. Check raspistill 3D mode: 100 | 101 | `raspistill -3d sbs -o 1.jpg` 102 | 103 | You should see 5 seconds preview, and stereoscopic image "1.jpg" should be saved after 104 | running this code. 105 | 106 | #### 9. How to avoid occasional stereoscopic support breaking? 107 | 108 | Stereoscopic support is broken on kernels from 4.19.57 and up to 4.19.97 109 | 110 | To fix it, just use "sudo rpi-update". This fix works from ~10 of April, 2020. 111 | 112 | Stay tuned! 113 | 114 | And good luck with your OpenCV experiments! :-) 115 | -------------------------------------------------------------------------------- /2_chess_cycle.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Eugene a.k.a. Realizator, stereopi.com, virt2real team 2 | # 3 | # This file is part of StereoPi tutorial scripts. 4 | # 5 | # StereoPi tutorial is free software: you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License 7 | # as published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # StereoPi tutorial is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with StereoPi tutorial. 17 | # If not, see . 18 | # 19 | # <><><> SPECIAL THANKS: <><><> 20 | # 21 | # Thanks to Adrian and http://pyimagesearch.com, as a lot of 22 | # code in this tutorial was taken from his lessons. 23 | # 24 | # Thanks to RPi-tankbot project: https://github.com/Kheiden/RPi-tankbot 25 | # 26 | # Thanks to rakali project: https://github.com/sthysel/rakali 27 | 28 | import os 29 | import time 30 | from datetime import datetime 31 | import picamera 32 | from picamera import PiCamera 33 | import cv2 34 | import numpy as np 35 | 36 | # User quit method message 37 | print("You can press 'Q' to quit this script.") 38 | 39 | # Photo session settings 40 | total_photos = 50 # Number of images to take 41 | countdown = 5 # Interval for count-down timer, seconds 42 | font=cv2.FONT_HERSHEY_SIMPLEX # Cowntdown timer font 43 | 44 | # Camera settimgs 45 | cam_width = 1280 # Cam sensor width settings 46 | cam_height = 480 # Cam sensor height settings 47 | 48 | # Final image capture settings 49 | scale_ratio = 1 50 | 51 | # Camera resolution height must be dividable by 16, and width by 32 52 | cam_width = int((cam_width+31)/32)*32 53 | cam_height = int((cam_height+15)/16)*16 54 | print ("Camera resolution: "+str(cam_width)+" x "+str(cam_height)) 55 | 56 | # Buffer for captured image settings 57 | img_width = int (cam_width * scale_ratio) 58 | img_height = int (cam_height * scale_ratio) 59 | capture = np.zeros((img_height, img_width, 4), dtype=np.uint8) 60 | print ("Scaled image resolution: "+str(img_width)+" x "+str(img_height)) 61 | 62 | # Initialize the camera 63 | camera = PiCamera(stereo_mode='side-by-side', stereo_decimate=False) 64 | camera.resolution=(cam_width, cam_height) 65 | camera.framerate = 20 66 | #camera.hflip = True 67 | 68 | # Lets start taking photos! 69 | counter = 0 70 | t2 = datetime.now() 71 | print ("Starting photo sequence") 72 | for frame in camera.capture_continuous(capture, format="bgra", \ 73 | use_video_port=True, resize=(img_width,img_height)): 74 | t1 = datetime.now() 75 | cntdwn_timer = countdown - int ((t1-t2).total_seconds()) 76 | 77 | # If cowntdown is zero - let's record next image 78 | if cntdwn_timer == -1: 79 | counter += 1 80 | filename = './scenes/scene_'+str(img_width)+'x'+str(img_height)+'_'+\ 81 | str(counter) + '.png' 82 | cv2.imwrite(filename, frame) 83 | print (' ['+str(counter)+' of '+str(total_photos)+'] '+filename) 84 | t2 = datetime.now() 85 | time.sleep(1) 86 | cntdwn_timer = 0 # To avoid "-1" timer display 87 | next 88 | 89 | # Draw cowntdown counter, seconds 90 | cv2.putText(frame, str(cntdwn_timer), (50,50), font, 2.0, (0,0,255),4, cv2.LINE_AA) 91 | cv2.imshow("pair", frame) 92 | key = cv2.waitKey(1) & 0xFF 93 | 94 | # Press 'Q' key to quit, or wait till all photos are taken 95 | if (key == ord("q")) | (counter == total_photos): 96 | break 97 | 98 | 99 | print ("Photo sequence finished") 100 | 101 | -------------------------------------------------------------------------------- /6_dm_video.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Eugene a.k.a. Realizator, stereopi.com, virt2real team 2 | # 3 | # This file is part of StereoPi tutorial scripts. 4 | # 5 | # StereoPi tutorial is free software: you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License 7 | # as published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # StereoPi tutorial is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with StereoPi tutorial. 17 | # If not, see . 18 | # 19 | # <><><> SPECIAL THANKS: <><><> 20 | # 21 | # Thanks to Adrian and http://pyimagesearch.com, as a lot of 22 | # code in this tutorial was taken from his lessons. 23 | # 24 | # Thanks to RPi-tankbot project: https://github.com/Kheiden/RPi-tankbot 25 | # 26 | # Thanks to rakali project: https://github.com/sthysel/rakali 27 | 28 | 29 | from picamera import PiCamera 30 | import time 31 | import cv2 32 | import numpy as np 33 | import json 34 | from datetime import datetime 35 | 36 | print ("You can press Q to quit this script!") 37 | time.sleep (5) 38 | 39 | # Depth map default preset 40 | SWS = 5 41 | PFS = 5 42 | PFC = 29 43 | MDS = -30 44 | NOD = 160 45 | TTH = 100 46 | UR = 10 47 | SR = 14 48 | SPWS = 100 49 | 50 | # Use the whole image or a stripe for depth map? 51 | useStripe = False 52 | dm_colors_autotune = True 53 | disp_max = -100000 54 | disp_min = 10000 55 | 56 | # Camera settimgs 57 | cam_width = 1280 58 | cam_height = 480 59 | 60 | # Final image capture settings 61 | scale_ratio = 0.5 62 | 63 | # Camera resolution height must be dividable by 16, and width by 32 64 | cam_width = int((cam_width+31)/32)*32 65 | cam_height = int((cam_height+15)/16)*16 66 | print ("Used camera resolution: "+str(cam_width)+" x "+str(cam_height)) 67 | 68 | # Buffer for captured image settings 69 | img_width = int (cam_width * scale_ratio) 70 | img_height = int (cam_height * scale_ratio) 71 | capture = np.zeros((img_height, img_width, 4), dtype=np.uint8) 72 | print ("Scaled image resolution: "+str(img_width)+" x "+str(img_height)) 73 | 74 | # Initialize the camera 75 | camera = PiCamera(stereo_mode='side-by-side',stereo_decimate=False) 76 | camera.resolution=(cam_width, cam_height) 77 | camera.framerate = 20 78 | #camera.hflip = True 79 | 80 | # Initialize interface windows 81 | cv2.namedWindow("Image") 82 | cv2.moveWindow("Image", 50,100) 83 | cv2.namedWindow("left") 84 | cv2.moveWindow("left", 450,100) 85 | cv2.namedWindow("right") 86 | cv2.moveWindow("right", 850,100) 87 | 88 | 89 | disparity = np.zeros((img_width, img_height), np.uint8) 90 | sbm = cv2.StereoBM_create(numDisparities=0, blockSize=21) 91 | 92 | 93 | def stereo_depth_map(rectified_pair): 94 | global disp_max 95 | global disp_min 96 | dmLeft = rectified_pair[0] 97 | dmRight = rectified_pair[1] 98 | disparity = sbm.compute(dmLeft, dmRight) 99 | local_max = disparity.max() 100 | local_min = disparity.min() 101 | if (dm_colors_autotune): 102 | disp_max = max(local_max,disp_max) 103 | disp_min = min(local_min,disp_min) 104 | local_max = disp_max 105 | local_min = disp_min 106 | print(disp_max, disp_min) 107 | disparity_grayscale = (disparity-local_min)*(65535.0/(local_max-local_min)) 108 | #disparity_grayscale = (disparity+208)*(65535.0/1000.0) # test for jumping colors prevention 109 | disparity_fixtype = cv2.convertScaleAbs(disparity_grayscale, alpha=(255.0/65535.0)) 110 | disparity_color = cv2.applyColorMap(disparity_fixtype, cv2.COLORMAP_JET) 111 | cv2.imshow("Image", disparity_color) 112 | key = cv2.waitKey(1) & 0xFF 113 | if key == ord("q"): 114 | quit(); 115 | return disparity_color 116 | 117 | def load_map_settings( fName ): 118 | global SWS, PFS, PFC, MDS, NOD, TTH, UR, SR, SPWS, loading_settings 119 | print('Loading parameters from file...') 120 | f=open(fName, 'r') 121 | data = json.load(f) 122 | SWS=data['SADWindowSize'] 123 | PFS=data['preFilterSize'] 124 | PFC=data['preFilterCap'] 125 | MDS=data['minDisparity'] 126 | NOD=data['numberOfDisparities'] 127 | TTH=data['textureThreshold'] 128 | UR=data['uniquenessRatio'] 129 | SR=data['speckleRange'] 130 | SPWS=data['speckleWindowSize'] 131 | #sbm.setSADWindowSize(SWS) 132 | sbm.setPreFilterType(1) 133 | sbm.setPreFilterSize(PFS) 134 | sbm.setPreFilterCap(PFC) 135 | sbm.setMinDisparity(MDS) 136 | sbm.setNumDisparities(NOD) 137 | sbm.setTextureThreshold(TTH) 138 | sbm.setUniquenessRatio(UR) 139 | sbm.setSpeckleRange(SR) 140 | sbm.setSpeckleWindowSize(SPWS) 141 | f.close() 142 | print ('Parameters loaded from file '+fName) 143 | 144 | 145 | load_map_settings ("3dmap_set.txt") 146 | try: 147 | npzfile = np.load('./calibration_data/{}p/stereo_camera_calibration.npz'.format(img_height)) 148 | except: 149 | print("Camera calibration data not found in cache, file ", './calibration_data/{}p/stereo_camera_calibration.npz'.format(img_height)) 150 | exit(0) 151 | 152 | imageSize = tuple(npzfile['imageSize']) 153 | leftMapX = npzfile['leftMapX'] 154 | leftMapY = npzfile['leftMapY'] 155 | rightMapX = npzfile['rightMapX'] 156 | rightMapY = npzfile['rightMapY'] 157 | 158 | 159 | 160 | # capture frames from the camera 161 | for frame in camera.capture_continuous(capture, format="bgra", use_video_port=True, resize=(img_width,img_height)): 162 | t1 = datetime.now() 163 | pair_img = cv2.cvtColor (frame, cv2.COLOR_BGR2GRAY) 164 | imgLeft = pair_img [0:img_height,0:int(img_width/2)] #Y+H and X+W 165 | imgRight = pair_img [0:img_height,int(img_width/2):img_width] #Y+H and X+W 166 | imgL = cv2.remap(imgLeft, leftMapX, leftMapY, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) 167 | imgR = cv2.remap(imgRight, rightMapX, rightMapY, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) 168 | 169 | if (useStripe): 170 | imgRcut = imgR [80:160,0:int(img_width/2)] 171 | imgLcut = imgL [80:160,0:int(img_width/2)] 172 | else: 173 | imgRcut = imgR 174 | imgLcut = imgL 175 | 176 | rectified_pair = (imgLcut, imgRcut) 177 | disparity = stereo_depth_map(rectified_pair) 178 | # show the frame 179 | cv2.imshow("left", imgLcut) 180 | cv2.imshow("right", imgRcut) 181 | 182 | t2 = datetime.now() 183 | print ("DM build time: " + str(t2-t1)) 184 | 185 | 186 | -------------------------------------------------------------------------------- /7_2d_map.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Eugene a.k.a. Realizator, stereopi.com, virt2real team 2 | # 3 | # This file is part of StereoPi tutorial scripts. 4 | # 5 | # StereoPi tutorial is free software: you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License 7 | # as published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # StereoPi tutorial is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with StereoPi tutorial. 17 | # If not, see . 18 | # 19 | # <><><> SPECIAL THANKS: <><><> 20 | # 21 | # Thanks to Adrian and http://pyimagesearch.com, as a lot of 22 | # code in this tutorial was taken from his lessons. 23 | # 24 | # Thanks to RPi-tankbot project: https://github.com/Kheiden/RPi-tankbot 25 | # 26 | # Thanks to rakali project: https://github.com/sthysel/rakali 27 | 28 | 29 | from picamera import PiCamera 30 | import time 31 | import cv2 32 | import numpy as np 33 | import json 34 | from datetime import datetime 35 | 36 | print ("You can press 'Q' to quit this script!") 37 | time.sleep (5) 38 | 39 | # Visualization settings 40 | showDisparity = True 41 | showUndistortedImages = True 42 | showColorizedDistanceLine = True 43 | 44 | # Depth map default preset 45 | SWS = 5 46 | PFS = 5 47 | PFC = 29 48 | MDS = -30 49 | NOD = 160 50 | TTH = 100 51 | UR = 10 52 | SR = 14 53 | SPWS = 100 54 | 55 | # Camera settimgs 56 | cam_width = 1280 57 | cam_height = 480 58 | 59 | # Final image capture settings 60 | scale_ratio = 0.5 61 | 62 | # Camera resolution height must be dividable by 16, and width by 32 63 | cam_width = int((cam_width+31)/32)*32 64 | cam_height = int((cam_height+15)/16)*16 65 | print ("Used camera resolution: "+str(cam_width)+" x "+str(cam_height)) 66 | 67 | # Buffer for captured image settings 68 | img_width = int (cam_width * scale_ratio) 69 | img_height = int (cam_height * scale_ratio) 70 | capture = np.zeros((img_height, img_width, 4), dtype=np.uint8) 71 | print ("Scaled image resolution: "+str(img_width)+" x "+str(img_height)) 72 | 73 | # Depth Map colors autotune 74 | autotune_min = 10000000 75 | autotune_max = -10000000 76 | 77 | # 3D points settings 78 | focal_length = 165.0 #taken from K matrix 79 | tx = 65 #taken from K matrix after calibration 80 | q = np.array([ 81 | [1, 0, 0, -img_width/2], 82 | [0, 1, 0, -img_height/2], 83 | [0, 0, 0, focal_length], 84 | [0, 0, -1/tx,0] 85 | ]) 86 | 87 | 88 | # Initialize the camera 89 | camera = PiCamera(stereo_mode='side-by-side',stereo_decimate=False) 90 | camera.resolution=(cam_width, cam_height) 91 | camera.framerate = 20 92 | #camera.hflip = True 93 | 94 | # Initialize interface windows 95 | cv2.namedWindow("Image") 96 | cv2.moveWindow("Image", 50,100) 97 | cv2.namedWindow("left") 98 | cv2.moveWindow("left", 450,100) 99 | cv2.namedWindow("right") 100 | cv2.moveWindow("right", 850,100) 101 | 102 | 103 | disparity = np.zeros((img_width, img_height), np.uint8) 104 | sbm = cv2.StereoBM_create(numDisparities=0, blockSize=21) 105 | 106 | def stereo_depth_map(rectified_pair): 107 | dmLeft = rectified_pair[0] 108 | dmRight = rectified_pair[1] 109 | disparity = sbm.compute(dmLeft, dmRight) 110 | local_max = disparity.max() 111 | local_min = disparity.min() 112 | #print(local_max, local_min) 113 | disparity_grayscale = (disparity-autotune_min)*(65535.0/(autotune_max-autotune_min)) 114 | disparity_fixtype = cv2.convertScaleAbs(disparity_grayscale, alpha=(255.0/65535.0)) 115 | disparity_color = cv2.applyColorMap(disparity_fixtype, cv2.COLORMAP_JET) 116 | if (showDisparity): 117 | cv2.imshow("Image", disparity_color) 118 | key = cv2.waitKey(1) & 0xFF 119 | if key == ord("q"): 120 | quit(); 121 | return disparity_color, disparity_fixtype, disparity 122 | 123 | def load_map_settings( fName ): 124 | global SWS, PFS, PFC, MDS, NOD, TTH, UR, SR, SPWS, loading_settings 125 | print('Loading parameters from file...') 126 | f=open(fName, 'r') 127 | data = json.load(f) 128 | SWS=data['SADWindowSize'] 129 | PFS=data['preFilterSize'] 130 | PFC=data['preFilterCap'] 131 | MDS=data['minDisparity'] 132 | NOD=data['numberOfDisparities'] 133 | TTH=data['textureThreshold'] 134 | UR=data['uniquenessRatio'] 135 | SR=data['speckleRange'] 136 | SPWS=data['speckleWindowSize'] 137 | #sbm.setSADWindowSize(SWS) 138 | sbm.setPreFilterType(1) 139 | sbm.setPreFilterSize(PFS) 140 | sbm.setPreFilterCap(PFC) 141 | sbm.setMinDisparity(MDS) 142 | sbm.setNumDisparities(NOD) 143 | sbm.setTextureThreshold(TTH) 144 | sbm.setUniquenessRatio(UR) 145 | sbm.setSpeckleRange(SR) 146 | sbm.setSpeckleWindowSize(SPWS) 147 | f.close() 148 | print ('Depth map settings has been loaded from the file '+fName) 149 | 150 | # Loading depth map settings 151 | load_map_settings ("3dmap_set.txt") 152 | 153 | # Loading stereoscopic calibration data 154 | try: 155 | npzfile = np.load('./calibration_data/{}p/stereo_camera_calibration.npz'.format(img_height)) 156 | except: 157 | print("Camera calibration data not found in cache, file ", './calibration_data/{}p/stereo_camera_calibration.npz'.format(img_height)) 158 | exit(0) 159 | 160 | imageSize = tuple(npzfile['imageSize']) 161 | leftMapX = npzfile['leftMapX'] 162 | leftMapY = npzfile['leftMapY'] 163 | rightMapX = npzfile['rightMapX'] 164 | rightMapY = npzfile['rightMapY'] 165 | QQ = npzfile['dispartityToDepthMap'] 166 | 167 | map_width = 320 168 | map_height = 240 169 | 170 | min_y = 10000 171 | max_y = -10000 172 | min_x = 10000 173 | max_x = -10000 174 | # Capture the frames from the camera 175 | for frame in camera.capture_continuous(capture, format="bgra", use_video_port=True, resize=(img_width,img_height)): 176 | t1 = datetime.now() 177 | pair_img = cv2.cvtColor (frame, cv2.COLOR_BGR2GRAY) 178 | imgLeft = pair_img [0:img_height,0:int(img_width/2)] #Y+H and X+W 179 | imgRight = pair_img [0:img_height,int(img_width/2):img_width] #Y+H and X+W 180 | imgL = cv2.remap(imgLeft, leftMapX, leftMapY, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) 181 | imgR = cv2.remap(imgRight, rightMapX, rightMapY, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) 182 | 183 | # Taking a strip from our image for lidar-like mode (and saving CPU) 184 | imgRcut = imgR [80:160,0:int(img_width/2)] 185 | imgLcut = imgL [80:160,0:int(img_width/2)] 186 | rectified_pair = (imgLcut, imgRcut) 187 | 188 | # Disparity map calculation 189 | disparity, disparity_bw, native_disparity = stereo_depth_map(rectified_pair) 190 | 191 | maximized_line = native_disparity 192 | 193 | maxInColumns = np.amax(maximized_line,0) 194 | points = cv2.reprojectImageTo3D(maxInColumns, QQ) 195 | xy_projection = np.zeros((map_height , map_width, 1), dtype=np.uint8) 196 | 197 | # "Jumping colors" protection for depth map visualization 198 | if autotune_max < np.amax(maximized_line): 199 | autotune_max = np.amax(maximized_line) 200 | if autotune_min > np.amin(maximized_line): 201 | autotune_min = np.amin(maximized_line) 202 | 203 | # Choose "closest" points in each column 204 | maximized_line[0:80,] = maxInColumns 205 | 206 | # Colorizing final line 207 | max_line_tune = (maximized_line-autotune_min)*(65535.0/(autotune_max-autotune_min)) 208 | max_line_gray = cv2.convertScaleAbs(max_line_tune, alpha=(255.0/65535.0)) 209 | 210 | # Put all points to the 2D map 211 | 212 | # Change map_zoom to adjust visible range! 213 | map_zoom_y = int(map_height/(max_y-min_y)) 214 | map_zoom_x = int(map_height/(max_x-min_x)) 215 | for n, points in enumerate(points): 216 | cur_y = -points[0][0] 217 | cur_x = points[0][1] 218 | max_y = max(cur_y, max_y) 219 | min_y = min(cur_y, min_y) 220 | max_x = max(cur_x, max_x) 221 | min_x = min(cur_x, min_x) 222 | xx = int(cur_x*map_zoom_x) + int(map_width/2) # zero point is in the middle of the map 223 | yy = map_height - int((cur_y-min_y)*map_zoom_y) # zero point is at the bottom of the map 224 | 225 | # If the point fits on our 2D map - let's draw it! 226 | if (xx < map_width) and (xx >= 0) and (yy < map_height) and (yy >= 0): 227 | xy_projection[yy, xx] = max_line_gray[0,n] 228 | 229 | #print ("min_y = " + str(min_y) + " max_y = " + str(max_y) + " zoom_x = " + str(map_zoom_x) + " zoom_y = " + str(map_zoom_y)) 230 | xy_projection_color = cv2.applyColorMap(xy_projection, cv2.COLORMAP_JET) 231 | max_line_color = cv2.applyColorMap(max_line_gray, cv2.COLORMAP_JET) 232 | 233 | # show the frame 234 | #print ("Autotune: min =", autotune_min, " max =", autotune_max) 235 | if (showUndistortedImages): 236 | cv2.imshow("left", imgLcut) 237 | cv2.imshow("right", imgRcut) 238 | if (showColorizedDistanceLine): 239 | cv2.imshow("Max distance line", max_line_color) 240 | cv2.imshow("XY projection", xy_projection_color) 241 | t2 = datetime.now() 242 | #print ("DM build time: " + str(t2-t1)) 243 | 244 | 245 | -------------------------------------------------------------------------------- /5_dm_tune.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Eugene a.k.a. Realizator, stereopi.com, virt2real team 2 | # 3 | # This file is part of StereoPi tutorial scripts. 4 | # 5 | # StereoPi tutorial is free software: you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License 7 | # as published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # StereoPi tutorial is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with StereoPi tutorial. 17 | # If not, see . 18 | # 19 | # <><><> SPECIAL THANKS: <><><> 20 | # 21 | # Thanks to Adrian and http://pyimagesearch.com, as a lot of 22 | # code in this tutorial was taken from his lessons. 23 | # 24 | # Thanks to RPi-tankbot project: https://github.com/Kheiden/RPi-tankbot 25 | # 26 | # Thanks to rakali project: https://github.com/sthysel/rakali 27 | 28 | 29 | import cv2 30 | import os 31 | from picamera.array import PiRGBArray 32 | from picamera import PiCamera 33 | from matplotlib import pyplot as plt 34 | from matplotlib.widgets import Slider, Button 35 | import numpy as np 36 | import json 37 | import time 38 | 39 | # Global variables preset 40 | imageToDisp = './scenes/dm-tune.jpg' 41 | photo_width = 640 42 | photo_height = 240 43 | image_width = 320 44 | image_height = 240 45 | 46 | image_size = (image_width,image_height) 47 | 48 | if os.path.isfile(imageToDisp) == False: 49 | print ('Can not read image from file \"'+imageToDisp+'\"') 50 | # No image! Let's take it... 51 | print ("Taking photo...") 52 | camera = PiCamera(stereo_mode='side-by-side',stereo_decimate=False) 53 | camera.resolution=(photo_width, photo_height) 54 | #camera.hflip = True 55 | time.sleep(1) 56 | camera.capture(imageToDisp) 57 | print ("Done!") 58 | 59 | pair_img = cv2.imread(imageToDisp,0) 60 | # Read image and split it in a stereo pair 61 | print('Read and split image...') 62 | imgLeft = pair_img [0:photo_height,0:image_width] #Y+H and X+W 63 | imgRight = pair_img [0:photo_height,image_width:photo_width] #Y+H and X+W 64 | 65 | # Implementing calibration data 66 | print('Read calibration data and rectifying stereo pair...') 67 | 68 | try: 69 | npzfile = np.load('./calibration_data/{}p/stereo_camera_calibration.npz'.format(image_height)) 70 | except: 71 | print("Camera calibration data not found in cache, file " & './calibration_data/{}p/stereo_camera_calibration.npz'.format(480)) 72 | exit(0) 73 | 74 | imageSize = tuple(npzfile['imageSize']) 75 | leftMapX = npzfile['leftMapX'] 76 | leftMapY = npzfile['leftMapY'] 77 | rightMapX = npzfile['rightMapX'] 78 | rightMapY = npzfile['rightMapY'] 79 | 80 | width_left, height_left = imgLeft.shape[:2] 81 | width_right, height_right = imgRight.shape[:2] 82 | 83 | if 0 in [width_left, height_left, width_right, height_right]: 84 | print("Error: Can't remap image.") 85 | 86 | imgL = cv2.remap(imgLeft, leftMapX, leftMapY, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) 87 | imgR = cv2.remap(imgRight, rightMapX, rightMapY, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) 88 | 89 | cv2.imshow('Left CALIBRATED', imgL) 90 | cv2.imshow('Right CALIBRATED', imgR) 91 | cv2.waitKey(0) 92 | 93 | rectified_pair = (imgL, imgR) 94 | 95 | 96 | # Depth map function 97 | SWS = 7 98 | PFS = 7 99 | PFC = 29 100 | MDS = -3 101 | NOD = 48 102 | TTH = 13 103 | UR = 3 104 | SR = 14 105 | SPWS = 2 106 | 107 | def stereo_depth_map(rectified_pair): 108 | print ('SWS='+str(SWS)+' PFS='+str(PFS)+' PFC='+str(PFC)+' MDS='+\ 109 | str(MDS)+' NOD='+str(NOD)+' TTH='+str(TTH)) 110 | print (' UR='+str(UR)+' SR='+str(SR)+' SPWS='+str(SPWS)) 111 | c, r = rectified_pair[0].shape 112 | disparity = np.zeros((c, r), np.uint8) 113 | sbm = cv2.StereoBM_create(numDisparities=16, blockSize=15) 114 | #sbm.SADWindowSize = SWS 115 | sbm.setPreFilterType(1) 116 | sbm.setPreFilterSize(PFS) 117 | sbm.setPreFilterCap(PFC) 118 | sbm.setMinDisparity(MDS) 119 | sbm.setNumDisparities(NOD) 120 | sbm.setTextureThreshold(TTH) 121 | sbm.setUniquenessRatio(UR) 122 | sbm.setSpeckleRange(SR) 123 | sbm.setSpeckleWindowSize(SPWS) 124 | dmLeft = rectified_pair[0] 125 | dmRight = rectified_pair[1] 126 | #cv2.FindStereoCorrespondenceBM(dmLeft, dmRight, disparity, sbm) 127 | disparity = sbm.compute(dmLeft, dmRight) 128 | #disparity_visual = cv.CreateMat(c, r, cv.CV_8U) 129 | local_max = disparity.max() 130 | local_min = disparity.min() 131 | print ("MAX " + str(local_max)) 132 | print ("MIN " + str(local_min)) 133 | disparity_visual = (disparity-local_min)*(1.0/(local_max-local_min)) 134 | local_max = disparity_visual.max() 135 | local_min = disparity_visual.min() 136 | print ("MAX " + str(local_max)) 137 | print ("MIN " + str(local_min)) 138 | #cv.Normalize(disparity, disparity_visual, 0, 255, cv.CV_MINMAX) 139 | #disparity_visual = np.array(disparity_visual) 140 | return disparity_visual 141 | 142 | 143 | # Set up and draw interface 144 | # Draw left image and depth map 145 | axcolor = 'lightgoldenrodyellow' 146 | fig = plt.subplots(1,2) 147 | plt.subplots_adjust(left=0.15, bottom=0.5) 148 | plt.subplot(1,2,1) 149 | dmObject = plt.imshow(rectified_pair[0], 'gray') 150 | 151 | saveax = plt.axes([0.3, 0.38, 0.15, 0.04]) #stepX stepY width height 152 | buttons = Button(saveax, 'Save settings', color=axcolor, hovercolor='0.975') 153 | 154 | 155 | def save_map_settings( event ): 156 | buttons.label.set_text ("Saving...") 157 | print('Saving to file...') 158 | result = json.dumps({'SADWindowSize':SWS, 'preFilterSize':PFS, 'preFilterCap':PFC, \ 159 | 'minDisparity':MDS, 'numberOfDisparities':NOD, 'textureThreshold':TTH, \ 160 | 'uniquenessRatio':UR, 'speckleRange':SR, 'speckleWindowSize':SPWS},\ 161 | sort_keys=True, indent=4, separators=(',',':')) 162 | fName = '3dmap_set.txt' 163 | f = open (str(fName), 'w') 164 | f.write(result) 165 | f.close() 166 | buttons.label.set_text ("Save to file") 167 | print ('Settings saved to file '+fName) 168 | 169 | buttons.on_clicked(save_map_settings) 170 | 171 | 172 | loadax = plt.axes([0.5, 0.38, 0.15, 0.04]) #stepX stepY width height 173 | buttonl = Button(loadax, 'Load settings', color=axcolor, hovercolor='0.975') 174 | def load_map_settings( event ): 175 | global SWS, PFS, PFC, MDS, NOD, TTH, UR, SR, SPWS, loading_settings 176 | loading_settings = 1 177 | fName = '3dmap_set.txt' 178 | print('Loading parameters from file...') 179 | buttonl.label.set_text ("Loading...") 180 | f=open(fName, 'r') 181 | data = json.load(f) 182 | sSWS.set_val(data['SADWindowSize']) 183 | sPFS.set_val(data['preFilterSize']) 184 | sPFC.set_val(data['preFilterCap']) 185 | sMDS.set_val(data['minDisparity']) 186 | sNOD.set_val(data['numberOfDisparities']) 187 | sTTH.set_val(data['textureThreshold']) 188 | sUR.set_val(data['uniquenessRatio']) 189 | sSR.set_val(data['speckleRange']) 190 | sSPWS.set_val(data['speckleWindowSize']) 191 | f.close() 192 | buttonl.label.set_text ("Load settings") 193 | print ('Parameters loaded from file '+fName) 194 | print ('Redrawing depth map with loaded parameters...') 195 | loading_settings = 0 196 | update(0) 197 | print ('Done!') 198 | 199 | buttonl.on_clicked(load_map_settings) 200 | 201 | # Building Depth Map for the first time 202 | disparity = stereo_depth_map(rectified_pair) 203 | 204 | plt.subplot(1,2,2) 205 | dmObject = plt.imshow(disparity, aspect='equal', cmap='jet') 206 | 207 | # Draw interface for adjusting parameters 208 | print('Start interface creation (it takes up to 30 seconds)...') 209 | 210 | SWSaxe = plt.axes([0.15, 0.01, 0.7, 0.025], facecolor=axcolor) #stepX stepY width height 211 | PFSaxe = plt.axes([0.15, 0.05, 0.7, 0.025], facecolor=axcolor) #stepX stepY width height 212 | PFCaxe = plt.axes([0.15, 0.09, 0.7, 0.025], facecolor=axcolor) #stepX stepY width height 213 | MDSaxe = plt.axes([0.15, 0.13, 0.7, 0.025], facecolor=axcolor) #stepX stepY width height 214 | NODaxe = plt.axes([0.15, 0.17, 0.7, 0.025], facecolor=axcolor) #stepX stepY width height 215 | TTHaxe = plt.axes([0.15, 0.21, 0.7, 0.025], facecolor=axcolor) #stepX stepY width height 216 | URaxe = plt.axes([0.15, 0.25, 0.7, 0.025], facecolor=axcolor) #stepX stepY width height 217 | SRaxe = plt.axes([0.15, 0.29, 0.7, 0.025], facecolor=axcolor) #stepX stepY width height 218 | SPWSaxe = plt.axes([0.15, 0.33, 0.7, 0.025], facecolor=axcolor) #stepX stepY width height 219 | 220 | sSWS = Slider(SWSaxe, 'SWS', 5.0, 255.0, valinit=5) 221 | sPFS = Slider(PFSaxe, 'PFS', 5.0, 255.0, valinit=5) 222 | sPFC = Slider(PFCaxe, 'PreFiltCap', 5.0, 63.0, valinit=29) 223 | sMDS = Slider(MDSaxe, 'MinDISP', -100.0, 100.0, valinit=-25) 224 | sNOD = Slider(NODaxe, 'NumOfDisp', 16.0, 256.0, valinit=128) 225 | sTTH = Slider(TTHaxe, 'TxtrThrshld', 0.0, 1000.0, valinit=100) 226 | sUR = Slider(URaxe, 'UnicRatio', 1.0, 20.0, valinit=10) 227 | sSR = Slider(SRaxe, 'SpcklRng', 0.0, 40.0, valinit=15) 228 | sSPWS = Slider(SPWSaxe, 'SpklWinSze', 0.0, 300.0, valinit=100) 229 | 230 | 231 | # Update depth map parameters and redraw 232 | def update(val): 233 | global SWS, PFS, PFC, MDS, NOD, TTH, UR, SR, SPWS 234 | SWS = int(sSWS.val/2)*2+1 #convert to ODD 235 | PFS = int(sPFS.val/2)*2+1 236 | PFC = int(sPFC.val/2)*2+1 237 | MDS = int(sMDS.val) 238 | NOD = int(sNOD.val/16)*16 239 | TTH = int(sTTH.val) 240 | UR = int(sUR.val) 241 | SR = int(sSR.val) 242 | SPWS= int(sSPWS.val) 243 | if ( loading_settings==0 ): 244 | print ('Rebuilding depth map') 245 | disparity = stereo_depth_map(rectified_pair) 246 | dmObject.set_data(disparity) 247 | print ('Redraw depth map') 248 | plt.draw() 249 | 250 | 251 | # Connect update actions to control elements 252 | sSWS.on_changed(update) 253 | sPFS.on_changed(update) 254 | sPFC.on_changed(update) 255 | sMDS.on_changed(update) 256 | sNOD.on_changed(update) 257 | sTTH.on_changed(update) 258 | sUR.on_changed(update) 259 | sSR.on_changed(update) 260 | sSPWS.on_changed(update) 261 | 262 | print('Show interface to user') 263 | plt.show() 264 | -------------------------------------------------------------------------------- /4_calibration_fisheye.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 Eugene a.k.a. Realizator, stereopi.com, virt2real team 2 | # 3 | # This file is part of StereoPi tutorial scripts. 4 | # 5 | # StereoPi tutorial is free software: you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License 7 | # as published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # StereoPi tutorial is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with StereoPi tutorial. 17 | # If not, see . 18 | # 19 | # <><><> SPECIAL THANKS: <><><> 20 | # 21 | # Thanks to Adrian and http://pyimagesearch.com, as a lot of 22 | # code in this tutorial was taken from his lessons. 23 | # 24 | # Thanks to RPi-tankbot project: https://github.com/Kheiden/RPi-tankbot 25 | # 26 | # Thanks to rakali project: https://github.com/sthysel/rakali 27 | 28 | 29 | import os 30 | import cv2 31 | import numpy as np 32 | 33 | 34 | 35 | 36 | # Global variables preset 37 | total_photos = 50 38 | 39 | # Camera resolution 40 | photo_width = 1280 41 | photo_height = 480 42 | 43 | # Image resolution for processing 44 | img_width = 320 45 | img_height = 240 46 | image_size = (img_width,img_height) 47 | 48 | # Chessboard parameters 49 | rows = 6 50 | columns = 9 51 | square_size = 2.5 52 | 53 | # Visualization options 54 | drawCorners = False 55 | showSingleCamUndistortionResults = True 56 | showStereoRectificationResults = True 57 | writeUdistortedImages = True 58 | imageToDisp = './scenes/scene_1280x480_1.png' 59 | 60 | # Calibration settings 61 | CHECKERBOARD = (6,9) 62 | 63 | subpix_criteria = (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1) 64 | calibration_flags = cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC+cv2.fisheye.CALIB_FIX_SKEW 65 | 66 | objp = np.zeros( (CHECKERBOARD[0]*CHECKERBOARD[1], 1, 3) , np.float64) 67 | objp[:,0, :2] = np.mgrid[0:CHECKERBOARD[0], 0:CHECKERBOARD[1]].T.reshape(-1, 2) 68 | 69 | _img_shape = None 70 | objpointsLeft = [] # 3d point in real world space 71 | imgpointsLeft = [] # 2d points in image plane. 72 | 73 | objpointsRight = [] # 3d point in real world space 74 | imgpointsRight = [] # 2d points in image plane. 75 | 76 | if (drawCorners): 77 | print("You can press 'Q' to quit this script.") 78 | 79 | 80 | # Main processing cycle 81 | # We process all calibration images and fill up 'imgpointsLeft' and 'objpointsRight' 82 | # arrays with found coordinates of the chessboard 83 | photo_counter = 0 84 | print ('Main cycle start') 85 | 86 | while photo_counter != total_photos: 87 | photo_counter = photo_counter + 1 88 | print ('Import pair No ' + str(photo_counter)) 89 | leftName = './pairs/left_'+str(photo_counter).zfill(2)+'.png' 90 | rightName = './pairs/right_'+str(photo_counter).zfill(2)+'.png' 91 | leftExists = os.path.isfile(leftName) 92 | rightExists = os.path.isfile(rightName) 93 | 94 | # If pair has no left or right image - exit 95 | if ((leftExists == False) or (rightExists == False)) and (leftExists != rightExists): 96 | print ("Pair No ", photo_counter, "has only one image! Left:", leftExists, " Right:", rightExists ) 97 | continue 98 | 99 | # If stereopair is complete - go to processing 100 | if (leftExists and rightExists): 101 | imgL = cv2.imread(leftName,1) 102 | loadedY, loadedX, clrs = imgL.shape 103 | grayL = cv2.cvtColor(imgL,cv2.COLOR_BGR2GRAY) 104 | gray_small_left = cv2.resize (grayL, (img_width,img_height), interpolation = cv2.INTER_AREA) 105 | imgR = cv2.imread(rightName,1) 106 | grayR = cv2.cvtColor(imgR,cv2.COLOR_BGR2GRAY) 107 | gray_small_right = cv2.resize (grayR, (img_width,img_height), interpolation = cv2.INTER_AREA) 108 | 109 | # Find the chessboard corners 110 | retL, cornersL = cv2.findChessboardCorners(grayL, CHECKERBOARD, cv2.CALIB_CB_ADAPTIVE_THRESH+cv2.CALIB_CB_FAST_CHECK+cv2.CALIB_CB_NORMALIZE_IMAGE) 111 | retR, cornersR = cv2.findChessboardCorners(grayR, CHECKERBOARD, cv2.CALIB_CB_ADAPTIVE_THRESH+cv2.CALIB_CB_FAST_CHECK+cv2.CALIB_CB_NORMALIZE_IMAGE) 112 | 113 | # Draw images with corners found 114 | if (drawCorners): 115 | cv2.drawChessboardCorners(imgL, (6,9), cornersL, retL) 116 | cv2.imshow('Corners LEFT', imgL) 117 | cv2.drawChessboardCorners(imgR, (6,9), cornersR, retR) 118 | cv2.imshow('Corners RIGHT', imgR) 119 | key = cv2.waitKey(0) 120 | if key == ord("q"): 121 | exit(0) 122 | 123 | # Here is a fix for the OpenCV bug, which is causing this error: 124 | # error:(-215:Assertion failed) fabs(norm_u1) > 0 in function 'InitExtrinsics' 125 | # It means corners are too close to the side of the image. Let's filter them out 126 | 127 | SayMore = False; #Should we print additional debug info? 128 | if ((retL == True) and (retR == True)): 129 | minRx = cornersR[:,:,0].min() 130 | maxRx = cornersR[:,:,0].max() 131 | minRy = cornersR[:,:,1].min() 132 | maxRy = cornersR[:,:,1].max() 133 | 134 | minLx = cornersL[:,:,0].min() 135 | maxLx = cornersL[:,:,0].max() 136 | minLy = cornersL[:,:,1].min() 137 | maxLy = cornersL[:,:,1].max() 138 | 139 | border_threshold_x = loadedX/7 140 | border_threshold_y = loadedY/7 141 | if (SayMore): 142 | print ("thr_X: ", border_threshold_x, "thr_Y:", border_threshold_y) 143 | x_thresh_bad = False 144 | if ((minRx photo_height): 168 | print ("Image resolution is higher than photo resolution, upscale needed. Please check your photo and image parameters!") 169 | exit (0) 170 | 171 | # Refine corners and add to array for processing 172 | if ((retL == True) and (retR == True)): 173 | objpointsLeft.append(objp) 174 | cv2.cornerSubPix(gray_small_left,cornersL,(3,3),(-1,-1),subpix_criteria) 175 | imgpointsLeft.append(cornersL) 176 | objpointsRight.append(objp) 177 | cv2.cornerSubPix(gray_small_right,cornersR,(3,3),(-1,-1),subpix_criteria) 178 | imgpointsRight.append(cornersR) 179 | else: 180 | print ("Pair No", photo_counter, "ignored, as no chessboard found" ) 181 | continue 182 | 183 | print ('End cycle') 184 | 185 | 186 | # This function calibrates (undistort) a single camera 187 | def calibrate_one_camera (objpoints, imgpoints, right_or_left): 188 | 189 | # Opencv sample code uses the var 'grey' from the last opened picture 190 | N_OK = len(objpoints) 191 | DIM= (img_width, img_height) 192 | K = np.zeros((3, 3)) 193 | D = np.zeros((4, 1)) 194 | rvecs = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(N_OK)] 195 | tvecs = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(N_OK)] 196 | 197 | # Single camera calibration (undistortion) 198 | rms, camera_matrix, distortion_coeff, _, _ = \ 199 | cv2.fisheye.calibrate( 200 | objpoints, 201 | imgpoints, 202 | grayL.shape[::-1], 203 | K, 204 | D, 205 | rvecs, 206 | tvecs, 207 | calibration_flags, 208 | (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 1e-6) 209 | ) 210 | # Let's rectify our results 211 | map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, D, np.eye(3), K, DIM, cv2.CV_16SC2) 212 | 213 | # Now we'll write our results to the file for the future use 214 | if (os.path.isdir('./calibration_data/{}p'.format(img_height))==False): 215 | os.makedirs('./calibration_data/{}p'.format(img_height)) 216 | np.savez('./calibration_data/{}p/camera_calibration_{}.npz'.format(img_height, right_or_left), 217 | map1=map1, map2=map2, objpoints=objpoints, imgpoints=imgpoints, 218 | camera_matrix=camera_matrix, distortion_coeff=distortion_coeff) 219 | return (True) 220 | 221 | 222 | # Stereoscopic calibration 223 | def calibrate_stereo_cameras(res_x=img_width, res_y=img_height): 224 | # We need a lot of variables to calibrate the stereo camera 225 | """ 226 | Based on code from: 227 | https://gist.github.com/aarmea/629e59ac7b640a60340145809b1c9013 228 | """ 229 | processing_time01 = cv2.getTickCount() 230 | objectPoints = None 231 | 232 | rightImagePoints = None 233 | rightCameraMatrix = None 234 | rightDistortionCoefficients = None 235 | 236 | leftImagePoints = None 237 | leftCameraMatrix = None 238 | leftDistortionCoefficients = None 239 | 240 | rotationMatrix = None 241 | translationVector = None 242 | 243 | imageSize= (res_x, res_y) 244 | 245 | TERMINATION_CRITERIA = (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 0.01) 246 | OPTIMIZE_ALPHA = 0.25 247 | 248 | try: 249 | npz_file = np.load('./calibration_data/{}p/stereo_camera_calibration.npz'.format(res_y)) 250 | except: 251 | pass 252 | 253 | for cam_num in [0, 1]: 254 | right_or_left = ["_right" if cam_num==1 else "_left"][0] 255 | 256 | try: 257 | print ('./calibration_data/{}p/camera_calibration{}.npz'.format(res_y, right_or_left)) 258 | npz_file = np.load('./calibration_data/{}p/camera_calibration{}.npz'.format(res_y, right_or_left)) 259 | 260 | list_of_vars = ['map1', 'map2', 'objpoints', 'imgpoints', 'camera_matrix', 'distortion_coeff'] 261 | print(sorted(npz_file.files)) 262 | 263 | if sorted(list_of_vars) == sorted(npz_file.files): 264 | print("Camera calibration data has been found in cache.") 265 | map1 = npz_file['map1'] 266 | map2 = npz_file['map2'] 267 | objectPoints = npz_file['objpoints'] 268 | if right_or_left == "_right": 269 | rightImagePoints = npz_file['imgpoints'] 270 | rightCameraMatrix = npz_file['camera_matrix'] 271 | rightDistortionCoefficients = npz_file['distortion_coeff'] 272 | if right_or_left == "_left": 273 | leftImagePoints = npz_file['imgpoints'] 274 | leftCameraMatrix = npz_file['camera_matrix'] 275 | leftDistortionCoefficients = npz_file['distortion_coeff'] 276 | else: 277 | print("Camera data file found but data corrupted.") 278 | except: 279 | #If the file doesn't exist 280 | print("Camera calibration data not found in cache.") 281 | return False 282 | 283 | 284 | print("Calibrating cameras together...") 285 | 286 | leftImagePoints = np.asarray(leftImagePoints, dtype=np.float64) 287 | rightImagePoints = np.asarray(rightImagePoints, dtype=np.float64) 288 | 289 | # Stereo calibration 290 | (RMS, _, _, _, _, rotationMatrix, translationVector) = cv2.fisheye.stereoCalibrate( 291 | objectPoints, leftImagePoints, rightImagePoints, 292 | leftCameraMatrix, leftDistortionCoefficients, 293 | rightCameraMatrix, rightDistortionCoefficients, 294 | imageSize, None, None, 295 | cv2.CALIB_FIX_INTRINSIC, TERMINATION_CRITERIA) 296 | # Print RMS result (for calibration quality estimation) 297 | print ("<><><><><><><><><><><><><><><><><><><><>") 298 | print ("<><> RMS is ", RMS, " <><>") 299 | print ("<><><><><><><><><><><><><><><><><><><><>") 300 | print("Rectifying cameras...") 301 | R1 = np.zeros([3,3]) 302 | R2 = np.zeros([3,3]) 303 | P1 = np.zeros([3,4]) 304 | P2 = np.zeros([3,4]) 305 | Q = np.zeros([4,4]) 306 | 307 | # Rectify calibration results 308 | (leftRectification, rightRectification, leftProjection, rightProjection, 309 | dispartityToDepthMap) = cv2.fisheye.stereoRectify( 310 | leftCameraMatrix, leftDistortionCoefficients, 311 | rightCameraMatrix, rightDistortionCoefficients, 312 | imageSize, rotationMatrix, translationVector, 313 | 0, R2, P1, P2, Q, 314 | cv2.CALIB_ZERO_DISPARITY, (0,0) , 0, 0) 315 | 316 | # Saving calibration results for the future use 317 | print("Saving calibration...") 318 | leftMapX, leftMapY = cv2.fisheye.initUndistortRectifyMap( 319 | leftCameraMatrix, leftDistortionCoefficients, leftRectification, 320 | leftProjection, imageSize, cv2.CV_16SC2) 321 | rightMapX, rightMapY = cv2.fisheye.initUndistortRectifyMap( 322 | rightCameraMatrix, rightDistortionCoefficients, rightRectification, 323 | rightProjection, imageSize, cv2.CV_16SC2) 324 | 325 | np.savez_compressed('./calibration_data/{}p/stereo_camera_calibration.npz'.format(res_y), imageSize=imageSize, 326 | leftMapX=leftMapX, leftMapY=leftMapY, 327 | rightMapX=rightMapX, rightMapY=rightMapY, dispartityToDepthMap = dispartityToDepthMap) 328 | return True 329 | 330 | # Now we have all we need to do stereoscopic fisheye calibration 331 | # Let's calibrate each camera, and than calibrate them together 332 | print ("Left camera calibration...") 333 | result = calibrate_one_camera(objpointsLeft, imgpointsLeft, 'left') 334 | print ("Right camera calibration...") 335 | result = calibrate_one_camera(objpointsRight, imgpointsRight, 'right') 336 | print ("Stereoscopic calibration...") 337 | result = calibrate_stereo_cameras() 338 | print ("Calibration complete!") 339 | 340 | # The following code just shows you calibration results 341 | # 342 | # 343 | 344 | if (showSingleCamUndistortionResults): 345 | 346 | """ 347 | # Takes an image in as a numpy array and undistorts it 348 | """ 349 | # NOTICE: we use 320x240 as a working resolution, regardless of 350 | # calibration images resolution. So 320x240 parameters are hardcoded 351 | # now. 352 | 353 | #h, w = imgL.shape[:2] 354 | w = 320 355 | h = 240 356 | print("Undistorting picture with (width, height):", (w, h)) 357 | try: 358 | npz_file = np.load('./calibration_data/{}p/camera_calibration{}.npz'.format(h, '_left')) 359 | if 'map1' and 'map2' in npz_file.files: 360 | #print("Camera calibration data has been found in cache.") 361 | map1 = npz_file['map1'] 362 | map2 = npz_file['map2'] 363 | else: 364 | print("Camera data file found but data corrupted.") 365 | exit(0) 366 | except: 367 | print("Camera calibration data not found in cache, file " & './calibration_data/{}p/camera_calibration{}.npz'.format(h, left)) 368 | exit(0) 369 | 370 | # We didn't load a new image from file, but use last image loaded while calibration 371 | undistorted_left = cv2.remap(gray_small_left, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) 372 | 373 | #h, w = imgR.shape[:2] 374 | print("Undistorting picture with (width, height):", (w, h)) 375 | try: 376 | npz_file = np.load('./calibration_data/{}p/camera_calibration{}.npz'.format(h, '_right')) 377 | if 'map1' and 'map2' in npz_file.files: 378 | #print("Camera calibration data has been found in cache.") 379 | map1 = npz_file['map1'] 380 | map2 = npz_file['map2'] 381 | else: 382 | print("Camera data file found but data corrupted.") 383 | exit(0) 384 | except: 385 | print("Camera calibration RIGHT data not found in cache.") 386 | exit(0) 387 | 388 | undistorted_right = cv2.remap(gray_small_right, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) 389 | 390 | cv2.imshow('Left UNDISTORTED', undistorted_left) 391 | cv2.imshow('Right UNDISTORTED', undistorted_right) 392 | cv2.waitKey(0) 393 | if (writeUdistortedImages): 394 | cv2.imwrite("undistorted_left.jpg",undistorted_left) 395 | cv2.imwrite("undistorted_right.jpg",undistorted_right) 396 | 397 | 398 | 399 | 400 | if (showStereoRectificationResults): 401 | # lets rectify pair and look at the result 402 | 403 | # NOTICE: we use 320x240 as a working resolution, regardless of 404 | # calibration images resolution. So 320x240 parameters are hardcoded 405 | # now. 406 | try: 407 | npzfile = np.load('./calibration_data/{}p/stereo_camera_calibration.npz'.format(240)) 408 | except: 409 | print("Camera calibration data not found in cache, file " & './calibration_data/{}p/stereo_camera_calibration.npz'.format(240)) 410 | exit(0) 411 | 412 | leftMapX = npzfile['leftMapX'] 413 | leftMapY = npzfile['leftMapY'] 414 | rightMapX = npzfile['rightMapX'] 415 | rightMapY = npzfile['rightMapY'] 416 | 417 | #read image to undistort 418 | photo_width = 640 419 | photo_height = 240 420 | image_width = 320 421 | image_height = 240 422 | image_size = (image_width,image_height) 423 | 424 | if os.path.isfile(imageToDisp) == False: 425 | print ('Can not read image from file \"'+imageToDisp+'\"') 426 | exit(0) 427 | 428 | pair_img = cv2.imread(imageToDisp,0) 429 | 430 | # If our image has width and height we need? 431 | height_check, width_check = pair_img.shape[:2] 432 | 433 | if (width_check != photo_width) and (height_check != photo_height): 434 | # It's not our size. If it is scaled? 435 | if (width_check/photo_width == height_check/photo_height): 436 | # Well, it's just scaled! Let's resize it to fit our needs 437 | pair_img = cv2.resize (pair_img, dsize=(photo_width, photo_height), interpolation = cv2.INTER_CUBIC) 438 | else: 439 | # Image can not be scaled, as calibration was done for another image size 440 | print ("Wrong image size. Please choose appropriate image.") 441 | exit (0) 442 | 443 | # Read image and split it in a stereo pair 444 | print('Read and split image...') 445 | imgLTest = pair_img [0:photo_height,0:image_width] #Y+H and X+W 446 | imgRTest = pair_img [0:photo_height,image_width:photo_width] #Y+H and X+W 447 | 448 | # If pair has been loaded and splitted correclty? 449 | width_left, height_left = imgLTest.shape[:2] 450 | width_right, height_right = imgRTest.shape[:2] 451 | if 0 in [width_left, height_left, width_right, height_right]: 452 | print("Error: Can't remap image.") 453 | 454 | # Rectifying left and right images 455 | imgL = cv2.remap(imgLTest, leftMapX, leftMapY, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) 456 | imgR = cv2.remap(imgRTest, rightMapX, rightMapY, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT) 457 | 458 | cv2.imshow('Left STEREO CALIBRATED', imgL) 459 | cv2.imshow('Right STEREO CALIBRATED', imgR) 460 | cv2.imwrite("rectifyed_left.jpg",imgL) 461 | cv2.imwrite("rectifyed_right.jpg",imgR) 462 | cv2.waitKey(0) 463 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------