diff --git a/src/script1.cpp b/src/script1.cpp index 7dcc28d..c984920 100644 --- a/src/script1.cpp +++ b/src/script1.cpp @@ -80,4 +80,3 @@ int main() fprintf(stderr, "Average FPS: %f\n", 1000 / avgFPS); return 0; } - diff --git a/src/script2.cpp b/src/script2.cpp index fb1e4f8..c3723f7 100644 --- a/src/script2.cpp +++ b/src/script2.cpp @@ -24,7 +24,8 @@ #include //#include #include - +#include +#include long long getTimestamp() { @@ -42,8 +43,7 @@ int main() int total_photos = 50;// # Number of images to take int countdown = 3;// # Interval for count-down timer, seconds int font = cv::FONT_HERSHEY_SIMPLEX;// # Cowntdown timer font - std::string folder_name = "/home/pi/stereopi-cpp-tutorial/"; - + std::string folder_name = "/home/pi/stereopi-cpp-tutorial/"; //Camera settimgs int cam_width = 1280;// # Cam sensor width settings int cam_height = 480;// # Cam sensor height settings @@ -76,6 +76,39 @@ int main() return 1; } + // Check if needed dirs exist. If do not - try to create them. + std::string scenesDir = folder_name + "scenes"; + std::string pairsDir = folder_name + "pairs"; + DIR* dir = opendir(scenesDir.c_str()); + if (dir) + { + closedir(dir); + } + else + { + int res = mkdir(scenesDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + if ( res == -1) + { + fprintf(stderr, "Cannot create Scenes dir!\n"); + return 1; + } + } + dir = opendir(pairsDir.c_str()); + if (dir) + { + closedir(dir); + } + else + { + int res = mkdir(pairsDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + if ( res == -1) + { + fprintf(stderr, "Cannot create Pairs dir!\n"); + return 1; + } + } + + int bufLen = cam_width * cam_height; char *buf = (char *)malloc(bufLen); int count = 0; @@ -93,6 +126,7 @@ int main() count = fread(buf, sizeof(*buf), bufLen, fp); if (count == 0) break; + cv::Mat frame(cam_height, cam_width, CV_8UC1, buf); long long t1 = getTimestamp(); int cntdwn_timer = countdown - (int)((t1-t2) / 1000000); diff --git a/src/script4.cpp b/src/script4.cpp index 66eefc6..d80e1d7 100644 --- a/src/script4.cpp +++ b/src/script4.cpp @@ -52,12 +52,10 @@ void calibrate_one_camera(std::vector > objpoints, std::v int N_OK = (int)objpoints.size(); cv::Size DIM(img_width, img_height); - cv::Mat K;// = cv::Mat::zeros(3, 3, CV_32FC1); - cv::Mat D;// = cv::Mat::zeros(4, 1, CV_32FC1); + cv::Mat K; + cv::Mat D; cv::Vec3f pt(0, 0, 0); - // std::vector rvecs(N_OK, pt); - // std::vector tvecs(N_OK, pt); cv::Mat rvecs = cv::Mat::zeros(N_OK, 1, CV_32FC3); cv::Mat tvecs = cv::Mat::zeros(N_OK, 1, CV_32FC3); @@ -164,6 +162,22 @@ bool calibrate_stereo_cameras(int res_x = img_width, int res_y = img_height) int main() { + // Check if calibration data folder exists. + DIR *dir = opendir(calibration_data_folder.c_str()); + if (dir) + { + closedir(calibration_data_folder); + } + else + { + int res = mkdir(calibration_data_folder.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + if (res == -1) + { + fprintf(stderr, "Cannot create calibration data folder!\n"); + return 1; + } + } + // Global variables preset int total_photos = 50; diff --git a/src/script6.cpp b/src/script6.cpp index 266d39a..7747609 100644 --- a/src/script6.cpp +++ b/src/script6.cpp @@ -80,11 +80,6 @@ void loadParams() bool stereo_depth_map(cv::Mat &left, cv::Mat &right, cv::Ptr bm, float &time1, float &time2, float &time3, float &time4) { - - - // cv::cvtColor(left, left, cv::COLOR_BGR2GRAY); - // cv::cvtColor(right, right, cv::COLOR_BGR2GRAY); - cv::Mat disp, disp8, colored; long long startT = getTimestamp(); bm->compute( left, right, disp); @@ -170,8 +165,6 @@ int main() float time1 = 0, time2 = 0, time3 = 0, time4 = 0, time5 = 0, time6 = 0, time7 = 0, time8 = 0, time9 = 0, time10 = 0, time11 = 0; int frameNumber = 0; - // while ((count = fread(buf, sizeof(*buf), bufLen, fp)) != 0) - // { while (true) { fseek(fp, -bufLen, SEEK_END); @@ -206,7 +199,7 @@ int main() time4 += timeShow - timeRectify; - // Taking a strip from our image for lidar-like mode (and saving CPU) + // Taking a strip from our image for lidar-like mode (and saving CPU) // cv::Mat imgLCut = cv::Mat(left, cv::Rect(0, 80, left.cols, 80)); // cv::Mat imgRCut = cv::Mat(right, cv::Rect(0, 80, right.cols, 80));