0

I have a class which receives frames taken with a camera. It then passes the frame to a camera calculator, which does some processing and crops according to the camera calculator's aspect ratio setting.

When I have...

@Override
public void receivePicture(Mat frame) {
    mCameraCalculator.processFrameForResult(frame);
    //the image is then saved   
}

//in camera calculator...
public void processFrameForResult(Mat frame){
    processFrame(frame);
    frame = frame.submat(getCenterByAspectRatio(frame)); //crop
}

The crop fails (the saved image is not cropped). However, when I have...

@Override
public void receivePicture(Mat frame) {
    mCameraCalculator.processFrameForResult(frame);
    frame = frame.submat(mCameraCalculator.getCenterByAspectRatio(frame)); //crop
    //the image is then saved   
}

//in camera calculator...
public void processFrameForResult(Mat frame){
    processFrame(frame);
}

It works perfectly. This does not make sense. Are these two bits of code not equivalent?

poppy
  • 247
  • 2
  • 15

1 Answers1

1

From the looks of it, receivePicture and processFrameForResult are in two different classes. In the top code block, you are doing the cropping in the CameraCalculator class. The trouble lies in the processFrameForResult method when you assign Frame. This line does not actually assign the cropped Frame back to the Frame variable, because once the method returns, the input Mat Frame variable it is no longer in scope. For more details on why this is, please see this post that goes into detail on the differences between pass by reference and pass by value.

If you would like the top code block to work, then your processFrameForResult method in the top code block must return the Mat Frame object instead of void.

sparkitny
  • 1,503
  • 4
  • 18
  • 23