这是用目标C ++编写的可编译代码的一部分
cv::Mat blurred(image);
medianBlur(image, blurred, 9);
cv::Mat gray0(blurred.size(), CV_8U), gray;
cv::vector<cv::vector<cv::Point> > contours;
for (int c = 0; c < 3; c++)
{
int ch[] = {c, 0};
mixChannels(&blurred, 1, &gray0, 1, ch, 1);
const int threshold_level = 2;
for (int l = 0; l < threshold_level; l++)
{
if (l == 0)
{
Canny(gray0, gray, 50, 150, 3);
dilate(gray, gray, cv::Mat(), cv::Point(-1,-1));
}
else
{
gray = gray0 >= (l+1) * 255 / threshold_level;
//这里是AppCode中的编译问题,但是代码可以编译并且可以正常工作...} ....
这是我用Java编写的方式,但是我停在了最后一行,我不明白并且不能用Java编写以正确地进行编译。即使在AppCode编辑器中,将其作为obecectiv-c代码也突出显示为错误,但编译时没有问题。因此,我认为AppCode解析器在理解它方面也存在问题,但是无论如何代码都可以正常工作,而且我也看到了AppCode解析器的其他问题,所以我不在乎,我使用静态导入,但是我需要了解的只是最后一行,代码继续更进一步,非常复杂...
Mat blurred = new Mat();
Imgproc.medianBlur(image, blurred, 9);
Mat gray0 = new Mat(blurred.size(), CvType.CV_8U);
Mat gray = new Mat();
Vector<Vector<Point>> contours = new Vector<>();
for (int c = 0; c < 3; c++) {
int ch[] = {c, 0};
Core.mixChannels(list(blurred), list(gray0), new MatOfInt(ch));
int threshold_level = 2;
for (int l = 0; l < threshold_level; l++) {
if (l == 0) {
Canny(gray0, gray, 50, 150, 3, false);
dilate(gray, gray, new Mat(), new Point(-1, -1), 1);
} else {
gray = gray0 >= (l + 1) * 255 / threshold_level; //here is compile problem and I don't understand line at all...
}
}
}
正如我在上面建议的那样,它看起来像cv :: Mat有一些重载的运算符,这些运算符隐藏了某些功能。此文档表明至少有一些运算符已超载。
这是该魔术系列在Java中的最终解决方案:
Core.compare(gray0, new Mat(gray0.size(), gray0.type(), new Scalar((l + 1) * 255 / threshold_level)), gray, Core.CMP_GE);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句