jboolean
Java_org_opencv_samples_NativeActivity_CvNativeActivity_BrightnessJNI (
JNIEnv* env, jobject thiz,
jint height, jint width, jintArray in, jintArray out)
{
jint* _in = env->GetIntArrayElements(in, 0);
jint* _out = env->GetIntArrayElements(out, 0);
//Build the Mat structure for input data
Mat mSrc(height, width, CV_8UC4, (unsigned char *)_in);
//Build the Mat structure for output data
Mat mOut(height, width, CV_8UC4, (unsigned char *)_out);
IplImage mSrcImg = mSrc;
IplImage moutImg = mOut;
IplImage *moutimg2,*b,*g,*r;
moutimg2 = cvCreateImage( cvGetSize(&mSrcImg), 8, 3 ) ;
b = cvCreateImage( cvGetSize(&mSrcImg), 8, 1 );
g = cvCreateImage( cvGetSize(&mSrcImg), 8, 1 );
r = cvCreateImage( cvGetSize(&mSrcImg), 8, 1 ) ;
cvSplit(&mSrcImg, b, g, r, 0 );
cvEqualizeHist( b, b );
cvEqualizeHist( g, g );
cvEqualizeHist( r, r );
cvMerge(b,g,r,0,moutimg2);
cvCvtColor(moutimg2, &moutImg, CV_BGR2GRAY);
env->ReleaseIntArrayElements(in, _in, 0);
env->ReleaseIntArrayElements(out, _out, 0);
return true;
}
を使用しているときに、コードを C++ インターフェイスに変換したいと考えていますJNI
。これは私のJavaコードです
public class CvNativeActivity extends Activity
{
public native boolean BrightnessJNI(int width, int height, int [] mPhotoIntArray, int [] mCannyOutArray);
static
{
System.loadLibrary("native_activity");
}
/** Called when the activity is first created. */
ImageView imageview_1;
ImageView imageview_2;
@Override
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;
is = this.getResources().openRawResource(R.drawable.foot);
Bitmap bmInImg = BitmapFactory.decodeStream(is);
int [] mPhotoIntArray;
int [] mCannyOutArray;
mPhotoIntArray = new int[bmInImg.getWidth() * bmInImg.getHeight()];
// Copy pixel data from the Bitmap into the 'intArray' array
bmInImg.getPixels(mPhotoIntArray, 0, bmInImg.getWidth(), 0, 0, bmInImg.getWidth(), bmInImg.getHeight());
//create the Brightness result buffer
mCannyOutArray = new int[bmInImg.getWidth() * bmInImg.getHeight()];
//
// Do Brightness
//
BrightnessJNI(bmInImg.getHeight(), bmInImg.getWidth(), mPhotoIntArray, mCannyOutArray);
//
// Convert the result to Bitmap
//
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);
//
// Save the result to file
//
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
String outFileName = extStorageDirectory + "/Brightness";
OutputBitmapToFile(bmOutImg, outFileName);
}
void OutputBitmapToFile(Bitmap InBm, String Filename)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
InBm.compress(Bitmap.CompressFormat.PNG, 100, bytes);
File f = new File(Filename);
try
{
f.createNewFile();
//write the bytes in file
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Cインターフェイスを使用しているときに、次のエラーが表示されます
OpenCV Error: Assertion failed <dst.data == dst0.data> in cvCvtColor, file ..\..\..\source\modules\imgproc\src\color.cpp, line 4422
Jni およびネイティブ android で C++ インターフェイスを使用できますか。どのサンプルも非常に感謝しています