Skip to content

Commit

Permalink
Merge PR #29 (#42)
Browse files Browse the repository at this point in the history
* fix(image.cpp): 🐛 incorrect image data copy

* test: 🧪 image data copy unittest

* fix: lint

* chore: 🍻 some code trick

---------

Co-authored-by: Ruitard <[email protected]>
  • Loading branch information
GACLove and ruitard authored May 5, 2023
1 parent c208c74 commit fe23f79
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
6 changes: 6 additions & 0 deletions cpp/tests/test_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ TEST_CASE("Image ops", "Image") {
REQUIRE(new_val.width() == black.cols);
REQUIRE(new_val.height() == black.rows);
REQUIRE(new_val.step() == black.step);
REQUIRE(std::memcmp(new_val.data(), black.data,
new_val.width() * new_val.height() *
new_val.elemSize()) == 0);

Image new_val2;
i_black.copyTo(&new_val2);
REQUIRE(new_val2.width() == black.cols);
REQUIRE(new_val2.height() == black.rows);
REQUIRE(new_val2.step() == black.step);
REQUIRE(std::memcmp(new_val2.data(), black.data,
new_val2.width() * new_val2.height() *
new_val2.elemSize()) == 0);
}

SECTION("image_to_opencv") {
Expand Down
13 changes: 7 additions & 6 deletions cpp/xrprimer/calibration/calibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ bool MultiCalibrator::Init() {
std::vector<cv::Point3f> p3ds;
for (int row = 0; row < pattern_size.height; row++)
for (int col = 0; col < pattern_size.width; col++)
p3ds.emplace_back(cv::Point3f(col * square_size.width,
row * square_size.height, 0.f));
p3ds.emplace_back(col * square_size.width,
row * square_size.height, 0.f);

int camId = 0;
// camera/points
Expand Down Expand Up @@ -349,7 +349,9 @@ struct ReprojCostFunctor {
void MultiCalibrator::OptimizeExtrinsics() {
printf("Start bundle.\n");
std::vector<Eigen::Vector3d> rs;
rs.reserve(pinhole_params.size());
std::vector<Eigen::Vector3d> ts;
ts.reserve(pinhole_params.size());
for (const auto &cam : pinhole_params) {
Eigen::AngleAxisf angleAxis(cam.extrinsic_r_);
rs.push_back(Eigen::Vector3f(angleAxis.axis() * angleAxis.angle())
Expand All @@ -366,10 +368,9 @@ void MultiCalibrator::OptimizeExtrinsics() {

ceres::Problem problem;
for (int img_idx = 0; img_idx < point2d_lists.size(); img_idx++) {
std::vector<std::vector<Eigen::Vector2f>> point2ds;
std::vector<std::vector<MathUtil::Matrix34f>> projs;
point2ds.resize(point_count);
projs.resize(point_count);
std::vector<std::vector<Eigen::Vector2f>> point2ds(point_count);
std::vector<std::vector<MathUtil::Matrix34f>> projs(point_count);

// triangulate
int cam_idx = 0;
for (const auto &iter : point2d_lists[img_idx]) {
Expand Down
11 changes: 5 additions & 6 deletions cpp/xrprimer/data_structure/image.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) OpenXRLab. All rights reserved.

#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <data_structure/image.h>
#include <map>
#include <memory>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <vector>

/**
Expand Down Expand Up @@ -93,9 +93,8 @@ class Image::Impl {

if (impl->format_ == format_ && impl->width_ == width_ &&
impl->height_ == height_) {
for (int h = 0; h < height_; ++h) {
memcpy(impl->data_, this->data_, impl->width_);
}

std::memcpy(impl->data_, this->data_, this->height_ * this->step_);

} else {
// TODO: mismatch format, maybe data is external
Expand Down
5 changes: 1 addition & 4 deletions cpp/xrprimer/data_structure/pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ Pose Pose::Scale(double s) const {
}

Eigen::Vector3d Pose::Center() const {
if (this) {
return -(this->quaternion_.inverse() * this->position_);
}
return Eigen::Vector3d::Zero();
return -(this->quaternion_.inverse() * this->position_);
}

void Pose::PoseMult(const Pose &lhs, const Pose &rhs) {
Expand Down

0 comments on commit fe23f79

Please sign in to comment.