opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.45k stars 5.76k forks source link

Integration issue with alphamat module #2535

Open sunitanyk opened 4 years ago

sunitanyk commented 4 years ago
System information (version)
Detailed description

There is a runtime issue while using the alphamat module in OpenCV4.3. It seems to be some resizing/cropping issue. Looks like only the top right of the input image is being processed.

The module works fine offline with the included example code, but does not give right results while being called directly as an OpenCV function call: cv::alphamat::infoFlow (InputArray image, InputArray tmap, OutputArray result) using OpenCV4.3 installation.

Input Images(RGB and trimap): plant

plant_trimap

Expected Output(as is obtained from testing the module code offline) plant_result_expected

Current Output from OpenCV4.3 function call : plant_result_Opencv4 3

This looks somewhat similar to images reported in an earlier issue( dynamic fusion running error! #2521)

nosajthenitram commented 4 years ago

Can you share your test code? I was able to get this to compile under Windows and would like to try what you're trying. Looking at the example, the same function is called, so I can't understand why your test would be different from the sample.

asmorkalov commented 4 years ago

@sunitanyk I tried the alphamat sample on Ubuntu 18.04 and Mac OS Catalina and output looks es expected for both cases. Images are attached. Could you provide version_string.tmp from your build directory? Do you use the example to reproduce the issue? mac_out

sunitanyk commented 4 years ago

Tried again with brew's opencv version 4.3.0_5 installation, and it works fine. Thanks.

zongking123 commented 4 years ago

@asmorkalov I tried the alphamat sample on Ubuntu 16.04 and opencv =>4.3.0,The module does not give right results while being called directly as an OpenCV function call: cv::alphamat::infoFlow (InputArray image, InputArray tmap, OutputArray result). Current Output from OpenCV4.3 function call : result Expected Output: plant_result

asmorkalov commented 4 years ago

@zongking123 Could you provide code to reproduce the issue and output of getBuildInformation call. Do you build OpenCV by your self?

similing4 commented 3 years ago

I'v got the same result when using cv::alphamat::infoFlow.Here is my code:

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/alphamat.hpp>

using namespace cv;
using namespace std;

int main(int argc, char** argv){
    if(argc < 4){
        printf("Please input your source file and mask file and output file,format:\n./convert input.png mask.png output.png\n");
        return 0;
    }
    Mat source = imread(argv[1]);
    Mat mask = imread(argv[2]);
    Mat output = Mat::zeros(source.size(), source.type());
    if(source.size().width!=mask.size().width || source.size().height!=mask.size().height) {
        printf("Your mask file size not match your source file,the source file size is %d*%d,but the mask size is %d*%d.\n",
            source.size().width,source.size().height,mask.size().width,mask.size().height);
        return 0;
    }

    //Convert Mat to float data type
    source.convertTo(source, CV_32FC3);
    mask.convertTo(mask, CV_32FC3);

    //main test method
    cv::alphamat::infoFlow(source, mask, output);

    //Display image
    imwrite(argv[3], output);
    printf("output: %s\n",argv[3]);

    return 0;
}
masterAllen commented 3 months ago

I also encountered this problem. After make tmap greyscale (8U3C to 8U1C), the output is correct.