@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
SoundPool sound = new SoundPool(1, AudioManager.STREAM_ALARM, 0);// maxStreams, streamType, srcQuality
int soundId_1 = sound.load(this, R.raw.to, 1);
int soundId_2 = sound.load(this, R.raw.re, 1);
int soundId_3 = sound.load(this, R.raw.me, 1);
int soundId_4 = sound.load(this, R.raw.pa, 1);
int soundId_5 = sound.load(this, R.raw.sol, 1);
int soundId_6 = sound.load(this, R.raw.ra, 1);
int soundId_7 = sound.load(this, R.raw.si, 1);
int soundId_8 = sound.load(this, R.raw.high_do, 1);
int result = 11;
if (inputFrame.rgba() != null) {
img_input = inputFrame.rgba();
if (img_result != null) img_result.release();
img_result = new Mat(inputFrame.rgba().rows(), inputFrame.rgba().cols(), CvType.CV_8UC1);
result = convertNativeLib(img_input.getNativeObjAddr(), img_result.getNativeObjAddr());
img_input.release();
switch (result) {
case 1:
sound.play(soundId_1, 1.0F, 1.0F, 0, 0, 1.0F);
sound.stop(soundId_1);
break;
case 2:
sound.play(soundId_2, 1.0F, 1.0F, 0, 0, 1.0F);
sound.stop(soundId_2);
break;
case 3:
sound.play(soundId_3, 1.0F, 1.0F, 0, 0, 1.0F);
sound.stop(soundId_3);
break;
case 4:
sound.play(soundId_4, 1.0F, 1.0F, 0, 0, 1.0F);
sound.stop(soundId_4);
break;
case 5:
sound.play(soundId_5, 1.0F, 1.0F, 0, 0, 1.0F);
sound.stop(soundId_5);
break;
case 6:
sound.play(soundId_6, 1.0F, 1.0F, 0, 0, 1.0F);
sound.stop(soundId_6);
break;
case 7:
sound.play(soundId_7, 1.0F, 1.0F, 0, 0, 1.0F);
sound.stop(soundId_7);
break;
case 8:
sound.play(soundId_8, 1.0F, 1.0F, 0, 0, 1.0F);
sound.stop(soundId_8);
break;
default:
break;
}
}
return img_result;
}
}
제가 안드로이드를 이용해 opencv를 하여 피아노 모양에 선을 추출해(허프라인이용) 소리를 내는 작업을 하고 있습니다 . ndk ,jni 를 이용해 c++로 opencv 소스를 활용하였고 소리 부분은 java 환경에 넘겨주어 soundpool로 각 계이름마다 소리를 내고 있습니다. 그런데 앱을 계속 켜 놓으면 화면이 바뀌지 않고 렉이 걸리면서 몇초 후에 어플이 종료 되는 경우가 발생합니다. 그 때 뜨는 에러가 (댓글에 썼습니다)
이렇습니다. 제생각에는 opencv를 사용하면서 메모리 부분에서 문제가 생기는 것같은데 어떻게 고쳐야 할지 모르겠습니다. 도와주세요 ㅠㅠ