# Problems loading a mesh with texture

**URL:** <https://forum.opencv.org/t/problems-loading-a-mesh-with-texture/3205>\
**Category:** C++\
**Created:** [May 7, 2021, 9:03am UTC](https://forum.opencv.org/t/problems-loading-a-mesh-with-texture/3205 "2021-05-07T09:03:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pauljurczak](https://avatars.discourse-cdn.com/v4/letter/p/87869e/32.png) [@pauljurczak](https://forum.opencv.org/u/pauljurczak)\
**Post date:** [May 7, 2021, 9:03am UTC](https://forum.opencv.org/t/problems-loading-a-mesh-with-texture/3205/1 "2021-05-07T09:03:49Z")

</div>

I’m loading an `.obj` mesh with a texture in `.png` image file ([Ignition Robotics](https://app.ignitionrobotics.org/mjcarroll/fuel/models/Banana%20for%20Scale)) and visualize it with this code snippet:

```auto
  Mesh mesh = Mesh::load("/home/paul/st/models/banana.obj", Mesh::LOAD_OBJ);
  Viz3d window{"Mesh"};

  mesh.texture = imread("/home/paul/st/models/banana.png", IMREAD_COLOR);

  window.setFullScreen();
  window.setBackgroundColor(Color::gray());
  window.showWidget("cs", WCoordinateSystem());
  window.showWidget("m", WMesh(mesh));
  window.resetCamera();
  window.spin();

```

The texture is badly applied:

![bad-banana](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/c/c28388c1ed4c40cdab928c01909078c1ba32363a.png)

Any idea what went wrong? The same pair of files: `banana.obj` and `banana.png`, renders fine with other applications.

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://avatars.discourse-cdn.com/v4/letter/p/87869e/32.png) [@pauljurczak](https://forum.opencv.org/u/pauljurczak)\
**Post date:** [May 7, 2021, 8:06pm UTC](https://forum.opencv.org/t/problems-loading-a-mesh-with-texture/3205/2 "2021-05-07T20:06:16Z")

</div>

Image memory layout provided by `imread` is not compatible with `cv::viz` or `.obj` requirements. Flipping the image around x-axis solves this problem:

```auto
  Mesh mesh = Mesh::load("/home/paul/st/models/banana.obj", Mesh::LOAD_OBJ);
  Mat tex, img = imread("/home/paul/st/models/banana.png", IMREAD_COLOR);
  Viz3d window{"Mesh"};

  flip(img, tex, 0);
  mesh.texture = tex;

```
