Ask Your Question

Need help resizing and blending two images (first attempt w/ OpenCV/Android)

asked 2012-06-26 10:46:02 -0500

Spooky gravatar image

updated 2012-06-26 22:07:48 -0500

I need a bit of help with my first attempt at using both OpenCV for Android and the Android NDK. What this ultimately needs to do is take two images: the first is a byte[] array from the Android camera (assume that it's the highest resolution the device's camera supports, which at this time, could be up to 13 to 15 MP). The second image is a bitmap that is a color filter (one or more of solid color, graduated, and/or split-field) with some level of opacity (alpha) already set.

Both need to be converted to Mat, and the filter image needs to be resized. I can either pass the desired size as an arg to main() or get it from the photo image. I know how to do the former, not the latter. After that, the two need to be blended in the same way as looking through the lens of an SLR or DSLR camera, with a color filter attached to the lens. (In Java/Android, that would be PorterDuff's SRC_OVER method.)

Finally, all three (the original photo, the resized filter, and the result, should be saved to png files (the path and basename will be passed as args): Original: path/basename-original.png Filter: path/basename-filter.png Result: path/basename.png

Here's what I have so far:

// angle brackets left out here because they hide the include files
// and just show include (and nothing after that) * 3.
#include cv.h
#include highgui.h
#include iostream

using namespace cv;

/// argv[1] is a byte[] array (photo image, jpg, ARGB_8888)
/// argv[2] is a bitmap (color filter, must resize, ARGB_8888)
/// argv[3] is the size for the resized bitmap
/// argv[4] is the path and basename for saving the output (ARGB_8888)
/// this should save the resulting image to path/basename.png and
///    return 0 for success, 1 for error

// oops....what I saw below was not what I typed....
int main (int argc, char **argv)  {
   double alpha = 0.5; double beta; double input;

   Mat src1, src2, dst;

   /// convert the photo and color filter to Mats here

   /// resize the filter image to match the specified size (matches
   /// photo)

   /// Blend the two images---should match the "blending" seen when
   /// looking through an SLR lens with a color filter in front

   beta = (1.0 - alpha);
   cvAddWeighted(src1, alpha, src2, beta, 0.0, dst);

   /// save resulting image here; also save unfiltered image and
   /// resized bitmaps.  Filenames:  path/basename-original.png,
   /// patn/basename-filter.png, and path/basename.png

   return 0;  // will ultimately return 0 for success, 1 for failure

Can someone who works with the Android NDK and OpenCV for Android please help me with this first attempt? This is my first time trying to use both, and after all the time I've spent trying to learn both, I'm still confused (that's primarily a result of the permanent aftermath from my first cancer, which really hosed my short-term memory, ability to concentrate, and much more.... Hopefully, if I get ... (more)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-07-07 01:02:44 -0500

rics gravatar image

For Android OpenCV connection I have written a small tutorial that works with version 2.3.1.

I have just uploaded here my solution for blending two images in Android using OpenCV.

edit flag offensive delete link more

Question Tools



Asked: 2012-06-26 10:46:02 -0500

Seen: 2,051 times

Last updated: Aug 17 '14