set color transparent in the android camera preview
Hello everybody
My target is to make an android application with openCV, that has a camera preview. In this preview i want to filter out a color range and set it transparent.
In the background of my application, (behind the camerapreview) is a static picture that should come through the transparent part of the camera preview.
For example, I want to filter out green and set it to transparent.
http://kotao-production.com">
Question 1: is it possible to make parts of the CvCameraViewFrame transparent?
Question 2: with respect to these answers: sustract color from Mat why is following code not working?
android activity:
public Mat onCameraFrame(CvCameraViewFrame inputFrame){
mRgba = inputFrame.rgba();
RemovePink(mRgba.getNativeObjAddr());
return mRgba;
}
public native void RemovePink( long matAddrRgba);
and the jni:
JNIEXPORT void JNICALL
Java_org_opencv_samples_tutorial2_Tutorial2Activity_RemovePink(JNIEnv*, jobject, jlong addrRgba);
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial2_Tutorial2Activity_RemovePink(JNIEnv*, jobject, jlong addrRgba){
Mat& mRgba = *(Mat*)addrRgba;
Mat alpha;
inRange(mRgba , Scalar(0,0,250), Scalar(0,0,255),alpha);
bitwise_not(alpha,alpha);
//split source
Mat bgr[4];
split(mRgba ,bgr);
//Merge to final image including alpha
Mat tmp[4] = { bgr[0],bgr[1],bgr[2],alpha};
merge(mRgba ,4,dst);
}
}
thanks in advance for every kind of help!
"Question 1: is it possible to make parts of the CvCameraViewFrame transparent?"
no. transparent against what ?
you'll have to compose the output from RemovePink() with another image (e,g the 'weathermap' image above) with respect to alpha, before showing it on CvCameraViewFrame.
again, your code is working fine. atm you're just not using the calculated alpha information