Help us understand the problem. What is going on with this article?

C++/OpenCV行列積の単純なミスについて error: (-13:Image step is wrong) Step must be a multiple of esz1 in function 'cv::Mat::Mat'

More than 1 year has passed since last update.

C++ / OpenCVで行列積を計算したら、

cv::Mat a = b * c;

Image step is wrongというエラーが出た。

OpenCV(3.4.5) C:\bin\opencv-3.4.5\sources\modules\core\include\opencv2/core/mat.inl.hpp:592: error: (-13:Image step is wrong) Step must be a multiple of esz1 in function 'cv::Mat::Mat'

原因は単純に、b.type()c.type()が違っていた。b.type() == CV_32F(float)、c.type() == CV_64F(double)でした。

OpenCVで行列積を計算するにはfloatまたはdoubleどちらかに合わせる必要がある。

typeをfloatに合わせたらちゃんと計算できた:smile:

// bはもともとCV_32FC1
c.convertTo(c, CV_32FC1);
cv::Mat a = b * c;

わかりにくいエラーメッセージでした:anguished:

maech
Robot R&D Engineer
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away