transparent addWeighted function on Android 4.4

asked 2015-11-18 20:10:27 -0500

Tim Pham gravatar image

Hi Seniors

I am trying to make a transparent image over a Mat, I am having android application that is capturing live camera, OpenCV said that addWeighted function can make image transparent, then I have implemented my code for it as below

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

   Mat mFrame = inputFrame.rgba(); //read from camera frame
   Mat mTransparent = new Mat(150, 200, 1, new Scalar(248, 248, 248)); `*//this is a frame that I want to overlay on mFrame*`

   Rect roi = new Rect(150, 200, 40, 60);
   Mat nFrame_roi = mFrame.submat(roi);
   Core.addWeighted(nFrame_roi, 0.8, mTransparent, 0.2, 1,  mFrame);

   return mFrame;

}

when test in Android the error occurs "Unfortunately, camera control has stopped"

Could you help me explain why the addWeighted function is not working well on Android? or any wrong in my code?

Thank a alot. Tim.

edit retag flag offensive close merge delete

Comments

Hi all,

I found solution for addWeighted function and display overlay Mat but it's not transparent, (opencv3.0.0, android 5.1)

my amendment code is: int count = 0; public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

    Mat mFrame = inputFrame.rgba();
    Mat n = inputFrame.rgba().colRange(10, 500).rowRange(10, 300).setTo(new Scalar(224, 224, 224));

    Imgproc.putText(n,  ", frame_" + count , new Point(50, 50), Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(255, 0, 255));
    n.copyTo(mFrame.submat(10, 300, 10, 500));
    Rect roi = new Rect(10, 10,  n.cols(),n.rows());
Core.addWeighted(mFrame.submat(roi), 0.8, n, 0.2, 1,  mFrame.submat(roi));
    return mFrame;

}

anyone tell me why it's not transparent? thanks Tim.

Tim Pham gravatar imageTim Pham ( 2015-11-20 01:25:44 -0500 )edit