set color transparent in the android camera preview

asked 2014-04-14 05:13:06 -0600

ntb-werz gravatar image

updated 2020-11-05 14:49:15 -0600

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.

image from <a href=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!

edit retag flag offensive close merge delete

Comments

1

"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

berak gravatar imageberak ( 2014-04-14 11:22:58 -0600 )edit