Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

problem with opencv.Imgproc in android studio

I am going to do a backgroundsubtractor in a ROI area on my phone's camera, here is part of the code:

public static final int x = 10;
public static final int y = 400;
public static final int width = 1260;
public static final int height = 550;

……

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    Mat frame = inputFrame.rgba();
    Mat fgMask = new Mat();
    Mat framecopy = frame.clone();
    Imgproc.cvtColor(framecopy, framecopy, Imgproc.COLOR_RGBA2GRAY);
    Mat ROI = framecopy.submat(y, y+height, x, x+width);
    backSub.apply(ROI, fgMask, -1);
    Imgproc.threshold(fgMask, fgMask, 127, 255, Imgproc.THRESH_BINARY);
    Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT,new Size( 3, 3));
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_CLOSE, kernel);
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_OPEN, kernel);
    return framecopy;}

Then i run it on my mobilephone, the result is that the whole screen shows the gray scale , not having a backgroundsub effect in the ROI. I heard that submat references from mat (here is framecopy), so i think the ROI region of the framecopy should have backgroundsub effect.

I am a beginner, who can tell me why ? Many thanks !

problem with opencv.Imgproc in android studio

I am going to do a backgroundsubtractor in a ROI area on my phone's camera, here is part of the code:

public static final int x = 10;
public static final int y = 400;
public static final int width = 1260;
public static final int height = 550;

……

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    Mat frame = inputFrame.rgba();
    Mat fgMask = new Mat();
    Mat framecopy = frame.clone();
    Imgproc.cvtColor(framecopy, framecopy, Imgproc.COLOR_RGBA2GRAY);
    Mat ROI = framecopy.submat(y, y+height, x, x+width);
    backSub.apply(ROI, fgMask, -1);
    Imgproc.threshold(fgMask, fgMask, 127, 255, Imgproc.THRESH_BINARY);
    Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT,new Size( 3, 3));
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_CLOSE, kernel);
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_OPEN, kernel);
    return framecopy;}

Then i run it on my mobilephone, the result is that the whole screen shows the gray scale , not having a backgroundsub effect in the ROI. I heard that submat references from mat (here is framecopy), so i think the ROI region of the framecopy should have backgroundsub effect.

I am a beginner, who can tell me why ? Many thanks !

problem with opencv.Imgproc in android studio

I am going to do a backgroundsubtractor in a ROI area on my phone's camera, here is part of the code:

public static final int x = 10;
public static final int y = 400;
public static final int width = 1260;
public static final int height = 550;

……

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    Mat frame = inputFrame.rgba();
    Mat fgMask = new Mat();
    Mat framecopy = frame.clone();
    Imgproc.cvtColor(framecopy, framecopy, Imgproc.COLOR_RGBA2GRAY);
    Mat ROI = framecopy.submat(y, y+height, x, x+width);
    backSub.apply(ROI, fgMask, -1);
    Imgproc.threshold(fgMask, fgMask, 127, 255, Imgproc.THRESH_BINARY);
    Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT,new Size( 3, 3));
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_CLOSE, kernel);
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_OPEN, kernel);
    return framecopy;}

Then i run it on my mobilephone, the result is that the whole screen shows the gray scale , not having a backgroundsub effect in the ROI. I heard that submat references from mat (here is framecopy), so i think the ROI region of the framecopy should have backgroundsub effect.

I am a beginner, who can tell me why ? Many thanks !

problem with opencv.Imgproc in android studio

I am going to do a backgroundsubtractor in a ROI area on my phone's camera, here is part of the code:

public static final int x = 10;
public static final int y = 400;
public static final int width = 1260;
public static final int height = 550;

……

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    Mat frame = inputFrame.rgba();
    Mat fgMask = new Mat();
    Mat framecopy = frame.clone();
    Imgproc.cvtColor(framecopy, framecopy, Imgproc.COLOR_RGBA2GRAY);
    Mat ROI = framecopy.submat(y, y+height, x, x+width);
    backSub.apply(ROI, fgMask, -1);
    Imgproc.threshold(fgMask, fgMask, 127, 255, Imgproc.THRESH_BINARY);
    Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT,new Size( 3, 3));
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_CLOSE, kernel);
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_OPEN, kernel);
    return framecopy;}

Then i run it on my mobilephone, the result is that the whole screen shows the gray scale , not having a backgroundsub effect in the ROI. I heard that submat references from mat (here is framecopy), so i think the ROI region of the framecopy should have backgroundsub effect.

I am a beginner, who can tell me why ? Many thanks !

problem with opencv.Imgproc opencv.core.mat in android studio

I am going to do a backgroundsubtractor in a ROI area on my phone's camera, here is part of the code:

public static final int x = 10;
public static final int y = 400;
public static final int width = 1260;
public static final int height = 550;

……

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    Mat frame = inputFrame.rgba();
    Mat fgMask = new Mat();
    Mat framecopy = frame.clone();
    Imgproc.cvtColor(framecopy, framecopy, Imgproc.COLOR_RGBA2GRAY);
    Mat ROI = framecopy.submat(y, y+height, x, x+width);
    backSub.apply(ROI, fgMask, -1);
    Imgproc.threshold(fgMask, fgMask, 127, 255, Imgproc.THRESH_BINARY);
    Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT,new Size( 3, 3));
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_CLOSE, kernel);
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_OPEN, kernel);
    return framecopy;}

Then i run it on my mobilephone, the result is that the whole screen just shows the gray scale , not having a backgroundsub effect in the ROI. I heard that submat references from mat (here is framecopy), so i think the ROI region of the framecopy should have backgroundsub effect.

I am a beginner, who can tell me why ? Many thanks !

problem with opencv.core.mat in android studio

I am going to do a backgroundsubtractor in a ROI area on my phone's camera, here is part of the code:

public static final int x = 10;
public static final int y = 400;
public static final int width = 1260;
public static final int height = 550;

……

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    Mat frame = inputFrame.rgba();
    Mat fgMask = new Mat();
    Mat framecopy = frame.clone();
    Imgproc.cvtColor(framecopy, framecopy, Imgproc.COLOR_RGBA2GRAY);
    Mat ROI = framecopy.submat(y, y+height, x, x+width);
    backSub.apply(ROI, fgMask, -1);
    Imgproc.threshold(fgMask, fgMask, 127, 255, Imgproc.THRESH_BINARY);
    Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT,new Size( 3, 3));
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_CLOSE, kernel);
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_OPEN, kernel);
    return framecopy;}

Then i run it on my mobilephone, the result is that the whole screen just shows the gray scale , not having a backgroundsub effect in the ROI. I heard that submat references from mat (here is framecopy), so i think the ROI region of the framecopy should have backgroundsub effect.

I am a beginner, who can tell me why ? Many thanks !

problem with opencv.core.mat How to do backgroundsub in the ROI of camera in android studio

I am going to do a backgroundsubtractor in a ROI area on my phone's camera, here is part of the code:

public static final int x = 10;
public static final int y = 400;
public static final int width = 1260;
public static final int height = 550;

……

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    Mat frame = inputFrame.rgba();
    Mat fgMask = new Mat();
    Mat framecopy = frame.clone();
    Imgproc.cvtColor(framecopy, framecopy, Imgproc.COLOR_RGBA2GRAY);
    Mat ROI = framecopy.submat(y, y+height, x, x+width);
    backSub.apply(ROI, fgMask, -1);
    Imgproc.threshold(fgMask, fgMask, 127, 255, Imgproc.THRESH_BINARY);
    Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT,new Size( 3, 3));
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_CLOSE, kernel);
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_OPEN, kernel);
    return framecopy;}

Then my camera resolution is 1280*960, the ROI is x(10:1270),y(400:960). After i run it the code on my mobilephone, the result is that the whole screen just shows the gray scale , not having a backgroundsub effect in the ROI. I heard that submat references from mat (here is framecopy), so i think the ROI region of the framecopy should have How to change the code, or is there any other better methods to realize the backgroundsub effect.

I am a beginner, who can tell me why ? in the ROI? Many thanks !here is part of the code:

public static final int x = 10;
public static final int y = 400;
public static final int width = 1260;
public static final int height = 560;

……

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    Mat frame = inputFrame.rgba();
    Mat fgMask = new Mat();
    Mat framecopy = frame.clone();
    Imgproc.cvtColor(framecopy, framecopy, Imgproc.COLOR_RGBA2GRAY);
    Mat ROI = framecopy.submat(y, y+height, x, x+width);
    backSub.apply(ROI, fgMask, -1);
    Imgproc.threshold(fgMask, fgMask, 127, 255, Imgproc.THRESH_BINARY);
    Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT,new Size( 3, 3));
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_CLOSE, kernel);
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_OPEN, kernel);
    return framecopy;}
click to hide/show revision 8
retagged

updated 2019-10-08 03:00:51 -0600

berak gravatar image

How to do backgroundsub in the ROI of camera in android studio

I am going to do a backgroundsubtractor in a ROI area on my phone's camera, my camera resolution is 1280*960, the ROI is x(10:1270),y(400:960). After i run the code on my mobilephone, the result is that the whole screen just shows the gray scale , not having a backgroundsub effect in the ROI. How to change the code, or is there any other better methods to realize the backgroundsub in the ROI? Many thanks !here is part of the code:

public static final int x = 10;
public static final int y = 400;
public static final int width = 1260;
public static final int height = 560;

……

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    Mat frame = inputFrame.rgba();
    Mat fgMask = new Mat();
    Mat framecopy = frame.clone();
    Imgproc.cvtColor(framecopy, framecopy, Imgproc.COLOR_RGBA2GRAY);
    Mat ROI = framecopy.submat(y, y+height, x, x+width);
    backSub.apply(ROI, fgMask, -1);
    Imgproc.threshold(fgMask, fgMask, 127, 255, Imgproc.THRESH_BINARY);
    Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT,new Size( 3, 3));
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_CLOSE, kernel);
    Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_OPEN, kernel);
    return framecopy;}