gpt4 book ai didi

java - 将 objective-c 代码转换为 java 会出现编译错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:54:13 24 4
gpt4 key购买 nike

这是用objective 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 有一些重载的运算符隐藏了一些功能。 This doc表明至少有一些运算符被重载。

这是该神奇行的 java 最终解决方案:

 Core.compare(gray0, new Mat(gray0.size(), gray0.type(), new Scalar((l + 1) * 255 / threshold_level)), gray, Core.CMP_GE);

关于java - 将 objective-c 代码转换为 java 会出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33709637/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com