[英]Assertion failed (scn == 3 || scn == 4) in void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int), file /../Linux/./../src/color.cpp, line 8000
I am trying to learn openCv with native code and I am taking reference from here .我正在尝试使用本机代码学习 openCv,我正在从这里获取参考。
I successfully build the project using ndk-build.我使用 ndk-build 成功构建了项目。
Now I want to make change in scan.cpp file which is responsible for getting point for image, crop it, scan it and set color.现在我想在scan.cpp文件中进行更改, 该文件负责获取图像点、裁剪、扫描和设置颜色。
I want to give different argument for line 321 in file which is我想为文件中的第 321 行提供不同的参数
cvtColor(mbgra, dst, CV_BGR2GRAY); cvtColor(mbgra, dst, CV_BGR2GRAY);
Can I give any other argument for CV_BGR2GRAY .我可以为CV_BGR2GRAY提供任何其他参数吗?
If yes HOW?如果是,如何? If no WHY?
如果没有,为什么?
Please guide me and tell me if I am missing anything.请指导我并告诉我是否遗漏了什么。 Thank you.
谢谢你。
Yes, you can give any argument you want.是的,你可以给出任何你想要的论点。 Would you get a reasonable output?
你会得到一个合理的输出吗? It depends.
这取决于。 CV_BGR2GRAY expects BGR (3 channel) input and will output gray (1 channel).
CV_BGR2GRAY 需要 BGR(3 通道)输入并将输出灰色(1 通道)。
If you input is 3 channel BGR (and even if it isn't really BGR, opencv won't care) you can use any 3 channel conversions, for example CV_BGR2HSV which would result in 3 channel HSV output.如果您输入的是 3 通道 BGR(即使它不是真正的 BGR,opencv 也不会关心),您可以使用任何 3 通道转换,例如 CV_BGR2HSV,这将导致 3 通道 HSV 输出。
If your input is 1 channel - than you won't be able to use BGR 2 GRAY obviously.如果您的输入是 1 通道 - 显然您将无法使用 BGR 2 GREY。
Mat bgraImage = imread("BGRA_IMAGE.png", -1); // 4 channel input image
Mat grayImage = imread("GRAY_IMAGE.png", CV_LOAD_IMAGE_GRAYSCALE); // 1 channel input image
Mat result;
cvtColor(bgraImage, result, CV_BGRA2GRAY); // CORRECT, input 4 channel, output will be 1 channel
cvtColor(bgraImage, result, CV_BGR2GRAY); // ALSO CORRECT
cvtColor(grayImage, result, CV_BGR2GRAY); // INCORRECT & will crash, input is 1 channel, expecting 3 or 4
cvtColor(grayImage, result, CV_GRAY2BGR); // CORRECT, input is 1 channel, output is 3 channel
You can see all possible color conversions here and read more about them here你可以看到所有可能的颜色转换这里和阅读更多关于他们在这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.