简体   繁体   中英

Converting objective-c code to java gives compile error

Here is part of compilable code writen in 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;

//here is compile problem in AppCode but code compiles ok and works... } ....

This is how I wrote it in java but I stopped on final line that I don't understand and cant write in java to be compiled correctly, Even in AppCode editor as obecectiv-c code it is highlighted as error but compiles without problem. So I think AppCode parser has problem to understand it also but anyway code works and I have seen other problems with AppCode parser so I don't care , I use static imports, but what i need to understand is just that final line, code continues further and is quite complex...

    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...
            }
        }
    }

As I suggested, above, it looks like cv::Mat has some overloaded operators that are hiding some functionality. This doc indicates that at least some operators are overloaded.

And this is final solution in java of that magic line:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM