Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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

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

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 this one part working, I SHOULD be able to do the rest on my own (should being the operative word here).

Thanks, --jim

click to hide/show revision 2
No.2 Revision

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

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

include cv.h

include highgui.h

include iostream

files #include cv.h #include highgui.h #include iostream using namespace cv;

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

error int main (int argc, char** argv) { double alpha = 0.5; double beta; double input;

input; Mat src1, src2, dst;

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

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

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

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

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

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 this one part working, I SHOULD be able to do the rest on my own (should being the operative word here).

Thanks, --jim

click to hide/show revision 3
fix a cancer #1 induced error in the pseudo-code I posted

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

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) 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 this one part working, I SHOULD be able to do the rest on my own (should being the operative word here).

Thanks, --jim