LoginSignup
2
0

More than 3 years have passed since last update.

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

Last updated at Posted at 2019-06-28

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:

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0