Calling up an image in an image View the resulting image
I am using Android NDK with OpenCV. I have two input images as input and one output image. The first input image is just a normal image and the second is a vignette.
I am getting some boolean error from java side.
Below is my java code:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageview_1=(ImageView) findViewById(R.id.imageView1);
imageview_2=(ImageView) findViewById(R.id.imageView2);
InputStream is , Vign;
is = this.getResources().openRawResource(R.drawable.me);
final Bitmap bmInImg = BitmapFactory.decodeStream(is);
Vign = this.getResources().openRawResource(R.drawable.p);
final Bitmap bmInImg2 = BitmapFactory.decodeStream(Vign);
mPhotoIntArray = new int[bmInImg.getWidth() * bmInImg.getHeight()];
nPhotoIntArray = new int[bmInImg.getWidth() * bmInImg.getHeight()];
vPhotoIntArray = new int[bmInImg2.getWidth() * bmInImg2.getHeight()];
imageview_1.setImageBitmap(bmInImg);
// Copy pixel data from the Bitmap into the 'intArray' array
bmInImg.getPixels(mPhotoIntArray, 0, bmInImg.getWidth(), 0, 0, bmInImg.getWidth(), bmInImg.getHeight());
bmInImg2.getPixels(vPhotoIntArray, 0, bmInImg2.getWidth(), 0, 0, bmInImg2.getWidth(), bmInImg2.getHeight());
mCannyOutArray = new int[bmInImg2.getWidth() * bmInImg2.getHeight()];
final Bitmap bmOutImg = Bitmap.createBitmap(bmInImg2.getWidth(), bmInImg2.getHeight(), Config.ARGB_8888);
bmOutImg.setPixels(mCannyOutArray, 0, bmInImg2.getWidth(), 0, 0, bmInImg2.getWidth(), bmInImg2.getHeight());
Button button= (Button) findViewById(R.id.NextButton);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (count ==0)
{
Vig(bmInImg.getHeight(),bmInImg.getWidth(),bmInImg2.getHeight(),bmInImg2.getWidth(), mPhotoIntArray,vPhotoIntArray, mCannyOutArray);
bmOutImg.setPixels(mCannyOutArray, 0, bmInImg2.getWidth(), 0, 0, bmInImg2.getWidth(), bmInImg2.getHeight());
imageview_2.setImageBitmap(bmOutImg);
}
count++;
}
});
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
String outFileName = extStorageDirectory + "/me.png";
OutputBitmapToFile(bmOutImg, outFileName);
}
The above code gives me a vignette as output, but the first image shows alignment across the whole image, and when I add both images, the vignette looks fine, but the image (image1) inside the vignette is filled with lines if I change the code bmOutImg.setPixels
from outer and inner conditions if
to
Vig(bmInImg.getHeight(),bmInImg.getWidth(),bmInImg2.getHeight(),bmInImg2.getWidth(), mPhotoIntArray,vPhotoIntArray, mCannyOutArray);
bmOutImg.setPixels(mCannyOutArray, 0, bmInImg.getWidth(), 0, 0, bmInImg.getWidth(), bmInImg.getHeight());
imageview_2.setImageBitmap(bmOutImg);
It then shows a vignette overlay on the image. It should be mine mCannyOutArray
should be so that both of my images give a satisfactory result for my output when I add vig + image
Vig:
and img1:
output:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:contentDescription="@null" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="235dp"
android:layout_height="208dp"
android:layout_weight="0.10"
android:contentDescription="@null" />
</LinearLayout>
source to share
First you need to determine where the problem is :
- Is this on your implementation of the vignette filter?
- Or is it a way to display images on the screen?
To help you with this, make sure that vig
and img1
are the same dimensions before being processed. Save these images to disk and check their width / height values.
Then execute your filter and save the output image to your hard drive before displaying it on the screen. If the saved image looks fine, then you know for sure that the problem is how the images are displayed.
While I have implemented a vignette filter using C ++ and OpenCV , you can take a look at the source code and compare it to what you are doing. Here's an example:
Input:
Output:
source to share