Skip to content

Commit

Permalink
rescale image
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoxiang12 committed May 25, 2019
1 parent 005060e commit 434a8bc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ch13/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ camera.cx: 325.1
camera.cy: 249.7

num_features: 150
num_features_init: 100
num_features_init: 50
num_features_tracking: 50
11 changes: 9 additions & 2 deletions ch13/src/dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ bool Dataset::Init() {
Vec3 t;
t << projection_data[3], projection_data[7], projection_data[11];
t = K.inverse() * t;
K = K * 0.5;
Camera::Ptr new_camera(new Camera(K(0, 0), K(1, 1), K(0, 2), K(1, 2),
t.squaredNorm(), SE3(SO3(), t)));
cameras_.push_back(new_camera);
Expand All @@ -61,9 +62,15 @@ Frame::Ptr Dataset::NextFrame() {
return nullptr;
}

cv::Mat image_left_resized, image_right_resized;
cv::resize(image_left, image_left_resized, cv::Size(), 0.5, 0.5,
cv::INTER_NEAREST);
cv::resize(image_right, image_right_resized, cv::Size(), 0.5, 0.5,
cv::INTER_NEAREST);

auto new_frame = Frame::CreateFrame();
new_frame->left_img_ = image_left;
new_frame->right_img_ = image_right;
new_frame->left_img_ = image_left_resized;
new_frame->right_img_ = image_right_resized;
current_image_index_++;
return new_frame;
}
Expand Down
4 changes: 2 additions & 2 deletions ch13/src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ int Frontend::TrackLastFrame() {
Mat error;
cv::calcOpticalFlowPyrLK(
last_frame_->left_img_, current_frame_->left_img_, kps_last,
kps_current, status, error, cv::Size(21, 21), 3,
kps_current, status, error, cv::Size(11, 11), 3,
cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 30,
0.01),
cv::OPTFLOW_USE_INITIAL_FLOW);
Expand Down Expand Up @@ -329,7 +329,7 @@ int Frontend::FindFeaturesInRight() {
Mat error;
cv::calcOpticalFlowPyrLK(
current_frame_->left_img_, current_frame_->right_img_, kps_left,
kps_right, status, error, cv::Size(21, 21), 3,
kps_right, status, error, cv::Size(11, 11), 3,
cv::TermCriteria(cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 30,
0.01),
cv::OPTFLOW_USE_INITIAL_FLOW);
Expand Down
13 changes: 7 additions & 6 deletions ch13/src/visual_odometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,9 @@ bool VisualOdometry::Init() {
void VisualOdometry::Run() {
while (1) {
LOG(INFO) << "VO is running";
auto t1 = std::chrono::steady_clock::now();
if (Step() == false) {
break;
}
auto t2 = std::chrono::steady_clock::now();
auto time_used =
std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
LOG(INFO) << "VO cost time: " << time_used.count() << " seconds.";
}

backend_->Stop();
Expand All @@ -62,7 +57,13 @@ bool VisualOdometry::Step() {
Frame::Ptr new_frame = dataset_->NextFrame();
if (new_frame == nullptr) return false;

return frontend_->AddFrame(new_frame);
auto t1 = std::chrono::steady_clock::now();
bool success = frontend_->AddFrame(new_frame);
auto t2 = std::chrono::steady_clock::now();
auto time_used =
std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
LOG(INFO) << "VO cost time: " << time_used.count() << " seconds.";
return success;
}

} // namespace myslam

0 comments on commit 434a8bc

Please sign in to comment.