0

Has anyone used the packaged Xamrin version of this? https://components.xamarin.com/view/emgucv-v3

I have recently purchased this license and am hitting exactly the same issues as described here ( Rotate camera preview to Portrait Android OpenCV Camera). Have been using a variety of approaches.

Firstly rotate the screen orientation from Landscape to Portrait, but this simply displays the stream in the same rotated form (90 degrees). Landscape seems to be the only one that works as I would like.

I have tried to rotate the camera itself using the camera object, but this doesn't fix the issue either. i.e.

camera.SetDisplayOrientation(90);

I have debuged this a huge number of times to see where execution occurs, and it seems that initially the screen is set correctly, but by the time

protected override void OnDraw(Android.Graphics.Canvas canvas)

is run to add the FPS text it has flipped it back.

I have also tried to flip the image using Matrix, but this drops the frame rate from approx 20FPS to about 6FPS. This is too much of. a hit

Really struggling here as this is now the major stumbling block to building out my app.

I am fairly new to Xamarin, so any help is greatly appreciated.

P.S. Apologies. I know this has been covered by another thread (Rotate camera preview to Portrait Android OpenCV Camera), and I have tried all the options there, but this entry was deleted by Ed Cotrell (Admin) from that thread and I was told to start a new one.

Community
  • 1
  • 1
Ben
  • 11
  • 2

1 Answers1

1

OK so I think I got it !!!

It appears the OpenCV sample in Xamarin uses the raw stream from the buffer, and by default that comes in on 90 degree angle regardless of what orientation you have the UI layout or setting/parameters for the camera.

So, I reworked the code within ProcessedCameraPreview

protected override void OnDraw(Android.Graphics.Canvas canvas)

Originally I was converting image object below to a native Android bitmap and rotating that. The performance hit was huge.

Image<Bgr, byte> image = _bgrBuffers.GetBuffer(0);

So, I figured out if I did the following :-

Image<Bgr, byte> rotateImage = image.Rotate(90, new Bgr(System.Drawing.Color.Black));
canvas.DrawBitmap(rotateImage.ToBitmap(), 0, 0, _paint);

It would render as required on the 90 degree angle. Performance impact was not really noticeable.

I now have the image object I need to perform the OpenCV functions I want to work with.

P.S. One other option worth noting that also worked was to rotate the Canvas using :-

Matrix matrix = new graphics.Matrix();
matrix.PostRotate(90);
DrawBitmap(image.ToBitmap(), matrix, _paint);

Again performance impact was not noticeable.

Ben
  • 11
  • 2