Giter VIP home page Giter VIP logo

Comments (2)

juangallostra avatar juangallostra commented on August 17, 2024

Hi @Allfu , glad you like it!

Current Status

As you can see here

if color is False:
cv2.fillConvexPoly(img, imgpts, DEFAULT_COLOR)

if color is False, which it is by default, I am using a single color to render the model, ignoring whatever colors have been defined in the model file.

The default color used to render the model is defined here:

DEFAULT_COLOR = (0, 0, 0)

Render Model with colors

If you only want to render the model with colors - assuming they have been defined in the .obj file - and not textures, you should call the render function with the last parameter set to True:

def render(img, obj, projection, model, color=False):

The call to the render function is done here:

frame = render(frame, obj, projection, model, False)

an example of a model with colors is the Pirate Ship (https://github.com/juangallostra/augmented-reality/blob/master/models/pirate-ship-fat.obj). Colors are defined in hex format:

To load colors you should also uncomment the lines:

#elif values[0] in ('usemtl', 'usemat'):
#material = values[1]

See below an example result of the Pirate Ship and Fox colored models:

imagen

test

The second one is taken from piotrekk94's fork: https://github.com/piotrekk94/tx2-ar, which has some other improvements.

Render model with textures

If what you want is to display a texture for the model, then yes, you should combine the OBJ model with the MTL file.

The code I am using to load OBJ models is based on this one: https://www.pygame.org/wiki/OBJFileLoader
As you can see in the link, there is a second class I removed which loads MTL files. In addition to that, lines

#elif values[0] == 'mtllib':
#self.mtl = MTL(values[1])

should be uncommented. The problem with textures is that you will then need OpenGL (or something similar) to render the model, which was work I didn't want to do at the time. It is possible, however, to do so.

This is a useful resource if you are wishing to dig deeper on how to do it: https://rdmilligan.wordpress.com/2015/10/15/augmented-reality-using-opencv-opengl-and-blender/

from augmented-reality.

Allfu avatar Allfu commented on August 17, 2024

got it!
thanks for your help!
thanks!

from augmented-reality.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.