Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/script1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,3 @@ int main()
fprintf(stderr, "Average FPS: %f\n", 1000 / avgFPS);
return 0;
}

40 changes: 37 additions & 3 deletions src/script2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#include <opencv2/imgproc.hpp>
//#include <stdio.h>
#include <unistd.h>

#include <dirent.h>
#include <sys/stat.h>

long long getTimestamp()
{
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
22 changes: 18 additions & 4 deletions src/script4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ void calibrate_one_camera(std::vector<std::vector<cv::Vec3f> > 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<cv::Vec3f> rvecs(N_OK, pt);
// std::vector<cv::Vec3f> 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);

Expand Down Expand Up @@ -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;

Expand Down
9 changes: 1 addition & 8 deletions src/script6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ void loadParams()
bool stereo_depth_map(cv::Mat &left, cv::Mat &right, cv::Ptr<cv::StereoBM> 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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));

Expand Down