#25575·opencv

when create new Mat with multi-channels(i.e., 8) with the particular value(i.e. 0.9), it will raise error (error: (-215:Assertion failed) cn <= 4 in function 'scalarToRawData')

Author: destinyzsCreated May 13, 2024Updated Sep 28, 2026
Labelsbugcategory: core

System Information

OpenCV version: 4.1.0 Operating System / Platform: Ubuntu 20.04

Detailed description

None

Steps to reproduce

cv::Mat y = cv::Mat(100, 100, CV_32FC(8), cv::Scalar(0.9));

It will raise error:

opencv-4.1.1/modules/core/src/array.cpp:3229: error: (-215:Assertion failed) cn <= 4 in function 'scalarToRawData'

But, if i create it like this, it success.

cv::Mat y = cv::Mat(100, 100, CV_32FC(8), cv::Scalar(0.));
y.setTo(0.9);

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)