Levi-Lesches / opencv_ffi

An FFI-based implementation of OpenCV in Dart
https://pub.dev/packages/opencv_ffi
Other
18 stars 1 forks source link

composed two images and add background color and gradient to given image functionality #20

Open sadaqatdev opened 11 months ago

sadaqatdev commented 11 months ago

@Levi-Lesches Thank you for the effort Can you please add the functionality to composed two images and also develop another method which add option to add gradient and colour to background of given image E.g the following is C++ example code

std::string composeImages(const std::string& base64Image1, const std::string& base64Image2) {
    // Decode Base64 strings to Mat objects efficiently
    cv::Mat mat1 = base64_decode_to_mat(base64Image1);
    cv::Mat mat2 = base64_decode_to_mat(base64Image2);

    // Create a new Mat with appropriate dimensions
    cv::Mat combinedMat(cv::Size(std::max(mat1.cols, mat2.cols), mat1.rows + mat2.rows), CV_8UC3);

    // Copy the image data efficiently
    mat1.copyTo(combinedMat(cv::Rect(0, 0, mat1.cols, mat1.rows)));
    mat2.copyTo(combinedMat(cv::Rect(0, mat1.rows, mat2.cols, mat2.rows)));

    // Encode the combined Mat back to Base64
    return mat_to_base64(combinedMat);
}

// Helper functions for Base64 encoding/decoding using a third-party library
cv::Mat base64_decode_to_mat(const std::string& base64Image) {
    std::vector<uchar> decodedData = base64_decode(base64Image);
    cv::Mat mat = cv::imdecode(decodedData, cv::IMREAD_COLOR);
    return mat;
}

std::string mat_to_base64(const cv::Mat& mat) {
    std::vector<uchar> encodedData;
    cv::imencode(".png", mat, encodedData);
    return base64_encode(encodedData);
}

Some help full links https://stackoverflow.com/questions/27296170/merge-two-mat-images-into-one

https://stackoverflow.com/questions/33239669/opencv-how-to-merge-two-images

Levi-Lesches commented 9 months ago

Hi, sorry for the delay.

I'm looking to restructure this package to more resemble the original OpenCV C++ SDK. When I do so, I will add these functions:

Hopefully in the next month.