gpt4 book ai didi

java - 结果显示图像上有衬里

转载 作者:太空宇宙 更新时间:2023-11-03 21:46:17 24 4
gpt4 key购买 nike

我正在使用 opencv 和 android ndk,下面是我的 jni 代码:

void Vignete(Mat& img1, Mat& img2, Mat& out)
{

resize(img1, img1, img2.size());
img1.convertTo(img1,CV_32FC4,1.0/255.0);
img2.convertTo(img2, CV_32FC4, 1.0/255.0);
vector<Mat> ch;
Mat I1;
split(img2,ch);
Mat alpha1 = ch[3];
Mat alpha = alpha1.clone();
Mat ch0 = ch[0];
Mat ch1 = ch[1];
Mat ch_2 = ch[2];
Mat ch_3 = ch[3];
cv::multiply(alpha,ch0,ch0);
cv::multiply(alpha,ch1,ch1);
cv::multiply(alpha,ch_2,ch_2);
cv::multiply(alpha,ch_3,ch_3);
vector<Mat> newVec;
newVec.push_back(ch0);
newVec.push_back(ch1);
newVec.push_back(ch_2);
newVec.push_back(ch_3);
merge(newVec, I1);
vector<Mat> ch2;
Mat I2;
split(img2,ch2);
Mat ch_0 = ch2[0];
Mat ch_1 = ch2[1];
Mat ch_21 = ch2[2];
Mat ch_31 = ch2[3];
cv::multiply(1.0-alpha,ch_0,ch_0);
cv::multiply(1.0-alpha,ch_1,ch_1);
cv::multiply(1.0-alpha,ch_21,ch_21);
cv::multiply(1.0-alpha,ch_31,ch_31);
vector<Mat> newVec1;
newVec1.push_back(ch_0);
newVec1.push_back(ch_1);
newVec1.push_back(ch_21);
newVec1.push_back(ch_31);
merge(newVec1, I2);
Mat result = I1+I2;
result.convertTo(out, CV_8UC4, 255);
}

下面是我的jni调用方法:

JNIEXPORT jint JNICALL Java_org_opencv_samples_NativeActivity_CvNativeActivity_Vig(
JNIEnv* env, jobject, jint width, jint height, jint i, jint j, jintArray in,jintArray inn,
jintArray out) {
jint* _in = env->GetIntArrayElements(in, 0);
jint* _inn = env->GetIntArrayElements(inn, 0);
jint* _out = env->GetIntArrayElements(out, 0);

Mat mSrc(height, width, CV_8UC4, (unsigned char*) _in);
Mat nSrc(i, j, CV_8UC4, (unsigned char*) _inn);
Mat bgra(height, width, CV_8UC4, (unsigned char*) _out);
Vite(mSrc,nSrc, bgra);
jint retVal;
int ret = 1;
retVal = jint(retVal);
return retVal;
}

结果:

enter image description here

我的 java 调用,其中 img1 是 快照中的图像 和 img2 图像 2 是 4 channel 的小插图 是输入,out 是输出

InputStream is , Vign;
is = this.getResources().openRawResource(R.drawable.me);
final Bitmap bmInImg = BitmapFactory.decodeStream(is);
Vign = this.getResources().openRawResource(R.drawable.vig2);
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);

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[bmInImg.getWidth() * bmInImg.getHeight()];
final Bitmap bmOutImg = Bitmap.createBitmap(bmInImg.getWidth(), bmInImg.getHeight(), Config.ARGB_8888);
bmOutImg.setPixels(mCannyOutArray, 0, bmInImg.getWidth(), 0, 0, bmInImg.getWidth(), bmInImg.getHeight());

Vig(bmInImg.getHeight(),bmInImg.getWidth(),bmInImg2.getHeight(),bmInImg2.getWidth(), mPhotoIntArray,vPhotoIntArray, mCannyOutArray);
Bitmap bmOutImg = Bitmap.createBitmap(bmInImg.getWidth(), bmInImg.getHeight(), Config.ARGB_8888);
bmOutImg.setPixels(mCannyOutArray, 0, bmInImg.getWidth(), 0, 0, bmInImg.getWidth(), bmInImg.getHeight());
imageview_2.setImageBitmap(bmOutImg);

图片 1:

enter image description here

img2:

enter image description here

我正在使用 eclipse 和 opencv android 版本 2.4.8 在 native 环境上工作。

最佳答案

检查你的两张图片是否大小相同,如果不是那么先resize两张图片然后执行操作,你需要在java端而不是在java端执行resize操作jni 端。结果图像的大小应为输入图像的大小,但第二个图像的大小也应为输入图像的大小,在这种情况下所有图像大小都很重要。

关于java - 结果显示图像上有衬里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25466319/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com