【发布时间】:2014-10-30 22:07:58
【问题描述】:
我正在使用带有 OpenCV 的 Android NDK。 我有两个输入图像作为输入和一个输出图像。 第一个输入图像只是普通图像,第二个是晕影。
我从 java 端收到某种逻辑错误。
下面是我的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);
}
上面的代码给了我很好的小插图作为输出,但是第一张图片在所有图像上都显示了衬里,当我添加两个图像时,小插图看起来很好但是小插图内的图像(image1)充满了线条,如果我更改代码bmOutImg.setPixels 从外部和内部条件if 到
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);
然后它在晕影图像上显示衬里。我的mCannyOutArray 应该是什么,这样当我添加 vig+image1 时,我的两个图像都能为我的输出提供令人满意的结果
维格是:
而 img1 是:
输出:
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>
【问题讨论】:
-
俗话说,一张图片胜过千言万语。
-
我用图片更新
-
带有“lining”的输出图像呢?
-
vig和img1的尺寸相同时是否还会出现问题? -
嘿@karlphillip 很高兴在我的问题上见到你,我只是在阅读你的答案,是的,如果我们使用
img1输出尺寸,输出将不会显示vig
标签: java android eclipse opencv image-processing