Opencv javacpp-presets findContours gives error: Unrecognized or unsupported array type in cvGetMat

Opencv javacpp-presets findContours gives error: Unrecognized or unsupported array type in cvGetMat

我正在尝试使用 opencv javacpp-presets(版本 3.0.0-1.0)从图像中提取文本(二值化)并使用下面的代码片段。 snippit 是代码 this python version 的翻译。

输入图像来自文件并通过 imread 加载,但代码在 findContours 失败并显示以下错误消息:

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file src\array.cpp, line 2494

here 建议的解决方案对我不起作用。非常感谢任何帮助!

    // Load the image
    Mat image_orig = imread(inputFile);
    if ( image_orig.empty() ) { LOGGER.error("Empty image!");}

    this.image = new Mat();
    //Add a border to the image for processing sake
    copyMakeBorder(image_orig, this.image, 50, 50, 50, 50, BORDER_CONSTANT);

    //# Calculate the width and height of the image

    this.img_y = this.image.arrayHeight();
    this.img_x = this.image.arrayWidth();

    if (DEBUG)
        LOGGER.info("Image is " + this.img_x + "x" + this.img_x);

    //Split out each channel
    Mat red = new Mat();
    Mat green = new Mat();
    Mat blue = new Mat();

    MatVector v = new MatVector(blue, green, red);
    split(image, v);

    //Run canny edge detection on each channel
    Mat blue_edges = new Mat();
    Canny(blue, blue_edges, 200, 250);

    Mat green_edges = new Mat();
    Canny(green, green_edges, 200, 250);

    Mat red_edges = new Mat();
    Canny(red, red_edges, 200, 250);

    //Join edges back into image
    Mat edges = new Mat();
    MatVector vEdges = new MatVector(red_edges, green_edges, blue_edges);
    merge(vEdges, edges);

    //Find the contours
    Mat edgesCopy = new Mat();
    edges.copyTo(edgesCopy);

    Mat hierarchy = new Mat();
    MatVector contours = new MatVector();
    findContours(edgesCopy, contours, hierarchy, RETR_TREE, CHAIN_APPROX_NONE);

天哪,我真傻。我应该使用来自 MatVector i.s.o 的输入。用于 Canny 检测的空垫子。然后使用灰度作为 @user3510227 建议我得到以下工作代码:

    // Load the image
    Mat image_orig = imread(inputFile);
    if ( image_orig.empty() ) { LOGGER.error("Empty image!");}

    this.image = new Mat();
    //Add a border to the image for processing sake
    copyMakeBorder(image_orig, this.image, 50, 50, 50, 50, BORDER_CONSTANT);

    //# Calculate the width and height of the image

    this.img_y = this.image.arrayHeight();
    this.img_x = this.image.arrayWidth();

    if (DEBUG)
        LOGGER.info("Image is " + this.img_x + "x" + this.img_x);

    //Split out each channel
    Mat red = new Mat();
    Mat green = new Mat();
    Mat blue = new Mat();

    MatVector v = new MatVector(red, green, blue);
    split(image, v);

    //Run canny edge detection on each channel
    Mat blue_edges = new Mat();
    Canny(v.get(0), blue_edges, 200, 250);
    Mat green_edges = new Mat();
    Canny(v.get(1), green_edges, 200, 250);
    Mat red_edges = new Mat();
    Canny(v.get(2), red_edges, 200, 250);

    //Join edges back into image
    Mat edges = new Mat();
    MatVector vEdges = new MatVector(red_edges, green_edges, blue_edges);
    merge(vEdges, edges);
    LOGGER.info("Type: " + edges.type());


    //convert to grayscale
    Mat gray = new Mat();
    cvtColor(edges, gray, COLOR_BGR2GRAY);
    Mat blur = new Mat();
    GaussianBlur(gray, blur, new Size(5,5), 0);
    Mat edgesCopy = new Mat();
    adaptiveThreshold(blur, edgesCopy, 255,1,1,11,2);


    //Find the contours        
    Mat hierarchy = new Mat();
    MatVector contours = new MatVector();

    findContours(edgesCopy, contours, hierarchy, RETR_TREE, CHAIN_APPROX_NONE);