0

I'm trying to display the center 1/3 of my phone's screen on real time, like this: https://i.stack.imgur.com/qDdAb.jpg

The idea is to limitate the user view to 1/3 of the screen, in the center (vertical). I've trying to do the precessing in the onCameraFrame method. I tried to create a ROI like this:

roi = new Rect(0, height/3, width, height/3);
mRgbaCropped = mRgba.submat(roi);
return mRgbaCropped; 

But all that I got is a black screen. Just to test I also tried to re-size the roi to:

roi = new Rect(50, 50, 50, 50); 

But no success. I'm not sure if what I'm doing is correct. What am i doing wrong?

Android89
  • 43
  • 6
  • try `roi = new Rect(width/3, 0, width/3, height);` You also probably need to copy that roi in the middle of a fullscreen white image. – Miki Sep 17 '15 at 17:16
  • Hi @Miki . I tried to set this new ROI as you mentioned, but unfortunately the app is crashing now.. – Android89 Sep 17 '15 at 17:40
  • Try also with the second part of the comment – Miki Sep 17 '15 at 17:41
  • @Miki, how do I create a new white Mat? – Android89 Sep 17 '15 at 17:43
  • something like `new Mat(height, width, CV_8UC4, new Scalar(255,255,255,255));` Not that sure about java syntax :D – Miki Sep 17 '15 at 17:53
  • just for testing: does your program display full image if you do `return mRgba; ` (to test whether you use the output of your mehod at all). If that works, can you try `return mRgbaCropped.clone(); ` for testing? Your code looks ok to me (although you might have swapped width/height as @Miki already corrected in his comment - not sure how smartphone images are oriented) – Micka Sep 17 '15 at 19:27
  • Great point @Micka . Yes I can display my mRgba just fine.I also tried the "return mRgbaCropped.clone();", and it didn't work. I also tried some ROI that I knew that would fit on my screen no matter the orientation (like this: roi = new Rect(50, 50, 50, 50); ) and no success yet – Android89 Sep 17 '15 at 19:59
  • I believe it's an Android syntax problem, I'm new to Opencv4Android – Android89 Sep 17 '15 at 20:02
  • does return mRgba.clone() work? does return new Mat (height, width, CV_8UC4, new Scalar (255,255,255,255)) work? – Micka Sep 17 '15 at 20:04
  • @Micka Tested the "return mRgba.clone()" and it's working. I had to adapt it to "new Mat (height, width,CvType.CV_8UC4, new Scalar (255,255,255,255));" and it worked just fine, the preview is a completely white screen! :) now I need to find a way to place the cropped 1/3 to this Mat – Android89 Sep 17 '15 at 20:33
  • use mRgba (yourRect).copyTo (whiteMat (yourRect)); – Micka Sep 17 '15 at 20:43
  • Hi @Micka I don't know what's going wrong. This is my FrameSize(320, 240). Look what I've done: ___mRgba = inputFrame.rgba();___Just for test--> roi = new Rect(100, 100, 100, 100) ; ___mRgbaCropped = mRgba.submat(roi); ___testCrop = new Mat (height, width,CvType.CV_8UC4, new Scalar (255,255,255,255));___ mRgbaCropped.copyTo(testCrop);___return testCrop; Does my logic make sense? Can't understand what's going wrong – Android89 Sep 18 '15 at 13:35
  • you must copy to the submat of testCrop... try `mRgbaCropped.copyTo(testCrop.submat(roi));` Otherwise, a new image is created with size of source image. – Micka Sep 18 '15 at 13:39
  • 1
    @Micka You're an OpenCV master! haha It worked! Thanks so much! – Android89 Sep 18 '15 at 13:59

0 Answers0