Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

why are mat operators seeing wrong type?

I'm at a loss here, why does my code crash with the error:

OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in cv::gemm, file C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\matmul.cpp, line 1530

Below is basically what I'm trying to do, some lines may be unnecessary but I've been removing all assumptions about auto-allocation and matrix depths. Note, live_image comes into my function as "const Mat" with depth CV_16U.

...

static Mat fused_image(live_image.rows, live_image.cols, live_image.type()); // this is my return Mat so same type

Mat gain_map(live_image.rows, live_image.cols, CV_32F); // gain_map gets the result of a blur() divided by 255.0

...

if (frame == 1) { live_image.copyTo(fused_image); // initialize on first pass thru function, they have same type } // else fused_image is generated by the remaining function code and retained for the next frame iteration

...

Mat flive_image(live_image.rows, live_image.cols, CV_32F); // declare my fp arrays

Mat ffused_image(live_image.rows, live_image.cols, CV_32F);

Mat fffused_image(live_image.rows, live_image.cols, CV_32F);

Mat invgain_map(live_image.rows, live_image.cols, CV_32F);

live_image.convertTo(flive_image, CV_32F); // should flive_image = live_image be equivalent?

fused_image.convertTo(ffused_image, CV_32F); // ditto, should now have fp versions of ushort arrays

invgain_map = -1.0 * gain_map + 1.0; // also tried "1.0 - gain_map;" as well as "gain_map.convertTo(invgain_map, -1, -1, 1);"

fffused_image = ffused_image * invgain_map; // crashes on this line, also tried C=A.mul(B) and multiply(A, B, C)

...

// note, fused_image would eventually be converted back to CV_16U from fffused_image after more matrix processing.

...

As noted it crashes on the last multiply line. When I replace * with multiply() I get a different but related error:

OpenCV Error: Bad argument (When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified) in cv::arithm_op, file C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\arithm.cpp, line 683

But how in the world can my types be different? I left nothing to chance. Thanks for any help.

why are mat operators seeing wrong type?

I'm at a loss here, why does my code crash with the error:

OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in cv::gemm, file C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\matmul.cpp, line 1530

1530

Below is basically what I'm trying to do, some lines may be unnecessary but I've been removing all assumptions about auto-allocation and matrix depths. Note, live_image comes into my function as "const Mat" with depth CV_16U.

...

   ...
  static Mat fused_image(live_image.rows, live_image.cols, live_image.type()); // this is my return Mat so same type

type Mat gain_map(live_image.rows, live_image.cols, CV_32F); // gain_map gets the result of a blur() divided by 255.0

...

255.0 ... if (frame == 1) { live_image.copyTo(fused_image); // initialize on first pass thru function, they have same type } // else fused_image is generated by the remaining function code and retained for the next frame iteration

...

iteration ... Mat flive_image(live_image.rows, live_image.cols, CV_32F); // declare my fp arrays

arrays Mat ffused_image(live_image.rows, live_image.cols, CV_32F);

CV_32F); Mat fffused_image(live_image.rows, live_image.cols, CV_32F);

CV_32F); Mat invgain_map(live_image.rows, live_image.cols, CV_32F);

CV_32F); live_image.convertTo(flive_image, CV_32F); // should flive_image = live_image be equivalent?

equivalent? fused_image.convertTo(ffused_image, CV_32F); // ditto, should now have fp versions of ushort arrays

arrays invgain_map = -1.0 * gain_map + 1.0; // also tried "1.0 - gain_map;" as well as "gain_map.convertTo(invgain_map, -1, -1, 1);"

1);" fffused_image = ffused_image * invgain_map; // crashes on this line, also tried C=A.mul(B) and multiply(A, B, C)

...

C) ... // note, fused_image would eventually be converted back to CV_16U from fffused_image after more matrix processing.

...

processing. ...

As noted it crashes on the last multiply line. When I replace * with multiply() I get a different but related error:

OpenCV Error: Bad argument (When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified) in cv::arithm_op, file C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\arithm.cpp, line 683

683

But how in the world can my types be different? I left nothing to chance. Thanks for any help.