opencv_contrib: Bug in sfm or data incorrect ?

Hi,

I am able to use sfm module on windows. I can run all examples. But I have got a problem using reconstruct function. I have got this exception

OpenCV Error: Assertion failed (data && dims <= 2 && (rows == 1 || cols == 1) && rows + cols - 1 == n && channels() == 1) in cv::Mat::operator class cv::Vec<double,2>, file G:\Lib\opencv\modules\core\include\opencv2/core/mat.inl.hpp, line 1221

I think you can reproduce using this code :

    vector<Mat> pt2d;
    pt2d.push_back((Mat_<double>(1, 16) << 64., 298., 560., 405., 271., 298., 514., 417., 651., 435., 561, 373., 497., 369., 350., 241));
    pt2d.push_back((Mat_<double>(1,16)<< 62., 272., 5.1840002441406250e+02, 4.1817602539062500e+02, 268.,266., 513., 359., 649., 371., 559., 227., 495., 229., 346., 205.));
    pt2d.push_back((Mat_<double>(1, 16) << 362., 185., 650., 304., 160., 248., 364., 192., 78., 146., 357.,176., 247., 402., 76., 149));
    pt2d.push_back((Mat_<double>(1, 16) << 668., 296., 5.9040000915527344e+01, 3.8880001831054688e+02,6.5520001220703125e+02, 2.6496002197265625e+02,
        4.9447909545898438e+02, 2.9382092285156250e+02,4.6800003051757813e+01, 9.9600006103515625e+01,5.1120001220703125e+02, 4.1280001831054688e+02,
        1.3080000305175781e+02, 2.4600001525878906e+02,2.6873861694335938e+02, 1.1197442626953125e+02 ));
    for (int i=0;i<pt2d.size();i++)
        pt2d[i]= pt2d[i].reshape(2);
    vector<Mat> Rs_est, ts_est, points3d_estimated
    Mat  K = (cv::Mat_<float>(3, 3) << 350, 0, 240, 0, 350, 360, 0, 0, 1);
    reconstruct(pt2d, Rs_est, points3d_estimated, K, true);

In debugging problem is here and should be something like points2d[frame].col(track).at<Vec2d>(0)

There is also this post . I don’t understand this function

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 21 (14 by maintainers)

Most upvoted comments

Sorry, is this still considered a bug?

It happens to me even when I simply copy the code from this official tutorial

P.S. I'm running everything on a docker container with this Dockerfile:
FROM debian:stable-slim

COPY backports.list /etc/apt/sources.list.d/

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev \
libavformat-dev libswscale-dev python3-dev python3-numpy libtbb2 libtbb-dev \
libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev ffmpeg

RUN apt-get install -y libboost-all-dev libeigen3-dev libgflags-dev libgoogle-glog-dev libatlas-base-dev \
libsuitesparse-dev libjpeg-dev libpng-dev libdc1394-22-dev

RUN git clone https://ceres-solver.googlesource.com/ceres-solver --depth=1 && \
git clone https://github.com/opencv/opencv.git --depth=1 && \
git clone https://github.com/opencv/opencv_contrib.git --depth=1

RUN apt-get install -y libvtk6-dev

RUN cd ceres-solver && \
mkdir build && \
cd build && \
cmake -D CXX11=ON \
-D EXPORT_BUILD_DIR=ON \
-D BUILD_TESTING=OFF .. && \
make -j8 && \
make install

RUN cd opencv && \
mkdir build && \
cd build && \
cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_CXX_FLAGS=-std=c++11 \
-D BUILD_TESTS=false \
-D BUILD_PERF_TESTS=false \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules  \
-D PYTHON3_EXECUTABLE=/usr/bin/python3 \
-D PYTHON_INCLUDE_DIR=/usr/include/python3.4m \
-D PYTHON_INCLUDE_DIR2=/usr/include/x86_64-linux-gnu/python3.4m \
-D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.4m.so \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/lib/python3/dist-packages/numpy/core/include/ \
-D CMAKE_INSTALL_PREFIX=/usr/local .. && \
make -j8 && \
make install

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]