문제

in the standard grabcut program that comes in the samples of opencv, I added a few lines of code to save the result to a file. However, nothing is there in the file. Just a black solid color. Here's the code that I put in --

in the main function

case 's':
    gcapp.writeToFile(writefilename);
    break;

in the GCApplication class

void writeToFile(string filename)
{
    imwrite(filename, mask);
    cout << "file written" << endl;
}  

I'm assuming that you know the grabcut program and you have the code to look at it. Please let me know if I need to post more info... thanks!

도움이 되었습니까?

해결책

You are saving the wrong cv::Mat. The one that is displayed at the end of showImage() is res, which is a local variable. You should make it a class variable, and then the method writeToFile() should execute:

imwrite(filename, res);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top