Ask Your Question
0

OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed

asked 2019-05-16 09:58:12 -0600

zxf gravatar image

Hello everyone, I have a error when I run a code that reads about 4,500 images and the error occurred when reading the 455th image. The error is

OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed) in reshape, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/matrix.cpp, line 1102 terminate called after throwing an instance of 'cv::Exception' what(): /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/matrix.cpp:1102: error: (-13) The matrix is not continuous, thus its number of rows can not be changed in function reshape

Could you give me some help,thanks a lot! And the code are as follows

#include "vo_features.h"
using namespace cv;
using namespace std;

#define MAX_FRAME 1000
#define MIN_NUM_FEAT 4540

int main( int argc, char** argv )   {

 // we work with grayscale images
  Mat img_1, img_2;
  Mat R_f, t_f; //the final rotation and tranlation vectors containing the 

  ofstream myfile;
  myfile.open ("results1_1.txt");

  double scale = 1.00;
  char filename1[200];
  char filename2[200];
  sprintf(filename1, "/home/zxf/vo/00/image_0/%06d.png", 0);
  sprintf(filename2, "/home/zxf/vo/00/image_0/%06d.png", 1);

  char text[100];
  int fontFace = FONT_HERSHEY_PLAIN;
  double fontScale = 1;
  int thickness = 1;  
  Point textOrg(10, 50);

  // we work with grayscale images
  //read the first two frames from the dataset
  img_1 = imread(filename1);
  img_2 = imread(filename2);

  if ( !img_1.data || !img_2.data ) { 
    std::cout<< " --(!) Error reading images " << std::endl; return -1;
  }

  // feature detection, tracking
  vector<Point2f> points1, points2;        //vectors to store the coordinates of the feature points
  featureDetection(img_1, points1);        //detect features in img_1
  vector<uchar> status;
  featureTracking(img_1,img_2,points1,points2, status); //track those features to img_2
  double focal = 718.8560;
  Point2d pp(607.1928, 185.2157);
  //recovering the pose and the essential matrix
  Mat E, R, t, mask;
  E = findEssentialMat(points2, points1, focal, pp, RANSAC, 0.999, 1.0, mask);
  recoverPose(E, points2, points1, R, t, focal, pp, mask);

  Mat prevImage = img_2;
  Mat currImage;
  vector<Point2f> prevFeatures = points2;
  vector<Point2f> currFeatures;
  char filename[100];
  R_f = R.clone();
  t_f = t.clone();

  clock_t begin = clock();
  namedWindow( "Road facing camera", WINDOW_AUTOSIZE );// Create a window for display.
  namedWindow( "Trajectory", WINDOW_AUTOSIZE );// Create a window for display.
  Mat traj = Mat::zeros(600, 600, CV_8UC3);

  for(int numFrame=2; numFrame < MAX_FRAME; numFrame++) {
    sprintf(filename, "/home/zxf/vo/00/image_0/%06d.png", numFrame);
        cout << numFrame << endl;
    Mat currImage_= imread(filename);
        Mat patchMatTmp3;

        currImage_.copyTo(patchMatTmp3);
        currImage= patchMatTmp3.reshape(0,0);
    vector<uchar> status;
    featureTracking(prevImage, currImage, prevFeatures, currFeatures, status);
    E = findEssentialMat(currFeatures, prevFeatures, focal, pp, RANSAC, 0.999, 1.0, mask);
    recoverPose(E, currFeatures, prevFeatures, R, t, focal, pp, mask);

        Mat prevPts(2,prevFeatures.size(), CV_64F), currPts(2,currFeatures.size(), CV_64F);
        for(int i=0;i<prevFeatures.size();i++)  {  
        prevPts.at<double>(0,i) = prevFeatures.at(i).x;
        prevPts.at<double>(1,i) = prevFeatures.at(i).y;

        currPts.at<double>(0,i) = currFeatures.at(i).x;
        currPts.at<double>(1,i) = currFeatures.at(i).y;
        }
    scale = 1;//getAbsoluteScale(numFrame, 0, t.at<double>(2));

        if ((scale>0.1)&&(t.at<double> ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-05-16 10:09:20 -0600

berak gravatar image

updated 2019-05-16 10:17:47 -0600

you MUST check the result of EACH AND EVERY imread() call.

Mat currImage_= imread(filename);
if (currImage_.empty()) // ;(

(it obviously failed in your case, copyTo() does not throw anything (baa!), and you end up with an exception in reshape(), a few lines down of the original problem.)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-05-16 09:58:12 -0600

Seen: 2,081 times

Last updated: May 16 '19