how to write an opencv function that take one image as paramater and returns 2 images

StackOverflow https://stackoverflow.com/questions/16470349

  •  21-04-2022
  •  | 
  •  

Domanda

i wanna build an opencv function that takes one IplImage image as parameter and returns 2 IplImage images. is this doable in opencv (c++). I prefer if it's using IplImage but i will appreciate other options

È stato utile?

Soluzione

You can return several images by passing them by reference as function arguments. Example:

void myFunction(const cv::Mat& input_image, cv::Mat &output1, cv::Mat &output2) {
    // modify output1
    input_image.copyTo(output1);
    rectangle(output1, cv::Rect(10,10,100,100), cv::Scalar(0,0,255), 2);

    // modify output2
    cvtColor(input_image,output2,CV_RGB2GRAY); 
}

int main() {
    cv::Mat input_image = imread("sample.jpg");
    cv::Mat out1, out2;

    myFunction(input_image, out1, out2);

    // now out1 and out2 are modified by myFunction
}

Example is for cv::Mat but you can do the same with IplImage. You should use cv::Mat instead of IplImage.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top