Forums - Adjusting aspect-ratio

4 posts / 0 new
Last post
Adjusting aspect-ratio
sagiv.philipp@g...
Join Date: 29 Feb 12
Posts: 9
Posted: Mon, 2012-04-02 04:03

Hi,
I'm currently testing the 'corner detection' demo, and I was wandring if I can adjust the aspect-ratio to match new window dimension from within 'surfaceChange' function?

I tried something like that:

glViewport(0, 0, width, height); //Reset The Current Viewport
glMatrixMode(GL_PROJECTION); //Select The Projection Matrix
glLoadIdentity(); 
//Calculate The Aspect Ratio Of The Window
gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 1000.0f);
glMatrixMode(GL_MODELVIEW); //Select The Modelview Matrix
glLoadIdentity(); 

 But I get compilation errors:

jni/FastCVSampleRenderer.cpp:230: error: 'GL_PROJECTION' was not declared in this scope

jni/FastCVSampleRenderer.cpp:230: error: 'glMatrixMode' was not declared in this scope

jni/FastCVSampleRenderer.cpp:231: error: 'glLoadIdentity' was not declared in this scope

 

Do I need to include some additional *.h file, or maybe there's a different way for adjusting the aspect-ration in GLES2

 

Thanks

  • Up0
  • Down0
Prasun_Choudhury
Join Date: 3 Dec 10
Posts: 15
Posted: Mon, 2012-04-02 17:15

You are using OpenGL (or OpenGL ES) functions in your application; so you need to include appropriate header files and dlls/libs for your program to compile and link properly. FastCV is not based on OpenGL or any other graphics API; so your program will not compile/link properly if you include other graphics API functions.

On your first question, FastCV is no way related to OpenGL function calls. What glPerspective does is, it sets the viewing volume of the scene that will be rendered and glViewport sets the 2D screen size on which the scene contents will be rendered. This is no way related with the input/output of the FastCV functions. To evaluate corner detection for a different image, you will have to update your image data. FastCV won't do it automatically for you and again it is no way connected with the OpenGL screen buffer data.

  • Up0
  • Down0
sagiv.philipp@g...
Join Date: 29 Feb 12
Posts: 9
Posted: Mon, 2012-04-02 23:01

 

Thank you for your reply.
It is totally clear that FastCV is no way related to OpenGL function calls, and if I'm using OpenGL (or ES) functions in my application I must include appropriate header files etc.

The reason I was asking my question in this forum was that by investigating FastCV Corner Detection Sample, I've noticed that whoever coded this sample had decided to use GLES2 (rather than GLES) function calls for the graphic part of the application, and since I couldn't find glMatrixMode in GLES2/*.h (it's implemented in GLES V.1.1) I thought it would be the right place to ask if someone knows whether I should also include GLES/*.h if I want to adjust the aspect-ratio or maybe I can do this differently.

Again, my question is not related to FascCV directly, but since FastCV implemented some sample which liked against GLES2 I assumed someone here will tell me if there's a different way to adjust the aspect-ratio with GLES V.2

Thanks

 

 

  • Up0
  • Down0
FedeCamposeco
Join Date: 24 Jul 12
Posts: 3
Posted: Wed, 2012-07-25 05:17

Hello!

In order to fix the aspect ratio of the display you don't need to change any of the native code. The "CameraSurface" class will create a surface for the camera to put its preview on. I believe that Android forbids any camera data access without content preview. To get around this (quite horribly IMHO) the "FastCVSampleRenderer" fills the entire screen with the native code output to hide this camera preview and the rest of the widgets are overlayed on the GLsurface (mGLSurface.setZOrderMediaOverlay(true)).

To easly change the aspect ratio of the render, change

surfaceChanged(w,h)

to

surfaceChanged(640,480)

(The program hardcodes this camera resolution through setupCamera() in "FastCVSample" class) Also you need to change the size of the CameraSurface preview to zero:

public void surfaceCreated( SurfaceHolder holder )
   {
      Log.d( TAG, "SurfaceCreated" );
      ViewGroup.LayoutParams params = this.getLayoutParams();
      params.width = 0;
      params.height = 0;
      this.setLayoutParams(params);
      try
      {
         if( camera != null )
         {
            camera.setPreviewDisplay( holder );
         }
      }
      catch( Exception exception )
      {
      }
   }

On the "CameraSurface" class. I also changed some minor stuff in the main.xml file to get everything centered and nice. If you want the modified source code, let me know.

Fede

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.