Cropping and save face from image using bounding box

reza1: <p>Hello</p>
<p>I have a project that through yolo   libtorch c++ I can identify the bounding box of an object that is personal. Now I want to crop and save the image of each bounding box so that I can pass this image to a function of the face recognition dll in C ++ that can return each person’s name.<br>
Thank you very much for your help on how I can write this code.<br>
I use the following code.</p>
<aside class="onebox githubblob" data-onebox-src="https://github.com/Nebula4869/YOLOv5-LibTorch/blob/master/src/YOLOv5LibTorch.cpp">
  <header class="source">

      <a href="https://github.com/Nebula4869/YOLOv5-LibTorch/blob/master/src/YOLOv5LibTorch.cpp" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/Nebula4869/YOLOv5-LibTorch/blob/master/src/YOLOv5LibTorch.cpp" target="_blank" rel="noopener nofollow ugc">Nebula4869/YOLOv5-LibTorch/blob/master/src/YOLOv5LibTorch.cpp</a></h4>


    <pre><code class="lang-cpp">#include &lt;opencv2/opencv.hpp&gt;
#include &lt;torch/script.h&gt;
#include &lt;algorithm&gt;
#include &lt;iostream&gt;
#include &lt;time.h&gt;


std::vector&lt;torch::Tensor&gt; non_max_suppression(torch::Tensor preds, float score_thresh=0.5, float iou_thresh=0.5)
{
        std::vector&lt;torch::Tensor&gt; output;
        for (size_t i=0; i &lt; preds.sizes()[0]; ++i)
        {
            torch::Tensor pred = preds.select(0, i);
            
            // Filter by scores
            torch::Tensor scores = pred.select(1, 4) * std::get&lt;0&gt;( torch::max(pred.slice(1, 5, pred.sizes()[1]), 1));
            pred = torch::index_select(pred, 0, torch::nonzero(scores &gt; score_thresh).select(1, 0));
            if (pred.sizes()[0] == 0) continue;

            // (center_x, center_y, w, h) to (left, top, right, bottom)
</code></pre>


  This file has been truncated. <a href="https://github.com/Nebula4869/YOLOv5-LibTorch/blob/master/src/YOLOv5LibTorch.cpp" target="_blank" rel="noopener nofollow ugc">show original</a>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>This is the code I added, but I do not know exactly how to crop the bounding box and recognize its face.</p>
<pre><code class="lang-auto">
importFunction ProcessFrame1;

   std::vector&lt;std::string&gt; result;

   HINSTANCE hinstLib;

   hinstLib = LoadLibrary(L"D:\\c++\\Project4\\x64\\Debug\\detect-camera-demo.dll");

   if (hinstLib == NULL) {
       printf("ERROR: unable to load DLL\n");
       return 1;
   }

   // Get function pointer
   ProcessFrame1 = (importFunction)GetProcAddress((hinstLib), "ProcessFrame");

   if (ProcessFrame1 == NULL) {
       printf("ERROR: unable to find DLL function\n");
       FreeLibrary(hinstLib);
       return 1;
   }

    

  //   Call function.
        result = ProcessFrame1(testcrop);


        for (size_t i = 0; i &lt; result.size(); i++)
        {
            std::cout &lt;&lt; " reslut name is : " &lt;&lt; result[i] &lt;&lt; "\n";
        }

        // Unload DLL file 
        FreeLibrary(hinstLib);
        
       

        cv::imwrite(" test_image.jpg", frame);

        /*if (cv::waitKey(1) == 27) break;*/
        
        cv::waitKey(10);
        system("pause");
    //}

    return 0;
}
</code></pre>