Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sadaqatdev opened this issue Jan 1, 2024 · 1 comment
Assignees
Labels
type: enhancement New feature or request

Comments

@sadaqatdev
Copy link

sadaqatdev commented Jan 1, 2024

@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

@sadaqatdev sadaqatdev changed the title composed two images and add background colour and gradient to given image functionality composed two images and add background color and gradient to given image functionality Jan 3, 2024
@Levi-Lesches
Copy link
Owner

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:

  • imencode/imdecode
  • base64_decode_to_mat
  • mat_to_base64
  • Mat::copyTo

Hopefully in the next month.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants