Ask Your Question
1

Image call from android to opencv

asked 2013-09-04 05:18:31 -0600

FLY gravatar image

updated 2014-09-05 17:13:39 -0600

I am using android ndk with opencv , I am giving two images as input and then one as output , my 2 input images are one is image and second is vignette , I am getting some kind of logical error from java side , below is my code of java

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);      
    }

Above code give me vignette fine but the first image output is showing lininng on all image and when i add both vignette look fine but image inside is full of lines , if i change the code of bmOutImg.setPixels from outside and inside condition 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);

Then it shows lining on vignette image. What should be my mCannyOutArray should be so that my both images show satisfactory result for my output.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-09-15 15:38:29 -0600

FLY gravatar image

updated 2014-09-15 15:39:16 -0600

The basic thing which I need to focus in my above question was to make all the images are of same size , after trying much and get helping from friends I got my error and my error which quote as logical error on java side was that I resize image on jni end but I need to resize it on java end so both images should be of same size , When both image are of same size then resultant image which is of same size of img1 (input image) don't show lines on resultant image

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-09-04 05:18:31 -0600

Seen: 510 times

Last updated: Sep 15 '14