Avoid use OpenCV for image, Convert Libtorch torch::Tensor to juce::image and like back

Pak_Lau: <p>Hello,<br>
I is use Libtorch for process image, OpenCV very large so try avoid.<br>
This i try make use:<br>
</p><aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/prabhuomkar/pytorch-cpp/blob/master/utils/image_io/src/image_io.cpp" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/prabhuomkar/pytorch-cpp/blob/master/utils/image_io/src/image_io.cpp" target="_blank" rel="nofollow noopener">prabhuomkar/pytorch-cpp/blob/master/utils/image_io/src/image_io.cpp</a></h4>
<pre><code class="lang-cpp">// Copyright 2020-present pytorch-cpp Authors
#include "image_io.h"
#include &lt;torch/torch.h&gt;

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"

#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb_image_resize.h"

namespace image_io {
namespace {
    void norm_ip(torch::Tensor img, double min, double max) {
        img.clamp_(min, max);
        img.sub_(min).div_(max - min + 1e-5);
    }

</code></pre>

  This file has been truncated. <a href="https://github.com/prabhuomkar/pytorch-cpp/blob/master/utils/image_io/src/image_io.cpp" target="_blank" rel="nofollow noopener">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>Not able to convert torch::Tensor to juce::image.<br>
I want to read a Video file, split into images on the fly and apply Deep Learning algorithm on image in Libtorch, then turn it back to image JUCE can understand. Anyone is have example make like this?</p>
<p>See also:<br>
</p><aside class="onebox allowlistedgeneric">
  <header class="source">
      <img src="https://aws1.discourse-cdn.com/business6/uploads/juce/optimized/2X/e/ee0de5c1ce7cb83fa639360afd244eb7312cec85_2_32x32.png" class="site-icon" width="32" height="32">
      <a href="https://forum.juce.com/t/convert-libtorch-torch-tensor-to-juce-image-and-like-back/41524/2" target="_blank" rel="nofollow noopener" title="12:03PM - 01 September 2020">JUCE – 1 Sep 20</a>
  </header>
  <article class="onebox-body">
    <img src="https://aws1.discourse-cdn.com/business6/uploads/juce/original/2X/8/81a3f97637164ed5cc736e21bd3fad7dccc0282d.svg" class="thumbnail onebox-avatar" width="120" height="120">

<h3><a href="https://forum.juce.com/t/convert-libtorch-torch-tensor-to-juce-image-and-like-back/41524/2" target="_blank" rel="nofollow noopener">Convert Libtorch torch::Tensor to juce::image and like back</a></h3>

<p>Really help is needed. I have this, first to oepncv  and then to juce::image (still crash). Any better way?  cv::Mat toOpenCV(at::Tensor out_tensor, int h, int w, int c) {           out_tensor = out_tensor.squeeze().permute({1, 2, 0});   cout...</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
Thanks you,

ptrblck: <p>Answer seems to be given <a href="https://github.com/prabhuomkar/pytorch-cpp/issues/64#issuecomment-686310810">here</a>.</p>