Jump to content

AI Based Object Redaction/Examples/Library Examples: Difference between revisions

mNo edit summary
Line 130: Line 130:


<syntaxhighlight lang=cpp>
<syntaxhighlight lang=cpp>
#include "rd/common/datatypes.hpp"
#include <rd/redaction.hpp>
#include "rd/common/ibackend.hpp"
#include "rd/common/ibuffer.hpp"
#include "rd/common/imodel.hpp"
#include "rd/common/runtimeerror.hpp"
 
/*Backend*/
#include "cpu/backend.hpp"
#include "gpu/backend.hpp"
 
/*io*/
#include "cpu/onnxfacedetect.hpp"
#include "cpu/redaction.hpp"
#include "gpu/onnxfacedetect.hpp"
#include "gpu/redaction.hpp"
#include "rd/common/ivideoinput.hpp"
#include "rd/io/v4l2/v4l2capture.hpp"


#include <unistd.h>
#include <unistd.h>
Line 158: Line 142:
#define INPUT_HEIGHT 720
#define INPUT_HEIGHT 720
#define INPUT_BPP 2
#define INPUT_BPP 2
#define CONVERT_WIDTH 640
#define CONVERT_HEIGHT 480


static void save_buffer(std::shared_ptr<rd::io::IBuffer> buffer,
static void save_buffer(std::shared_ptr<rd::io::IBuffer> buffer,
Line 202: Line 184:
   /* Buffers */
   /* Buffers */
   rd::Resolution input_resolution = rd::Resolution(INPUT_WIDTH, INPUT_HEIGHT);
   rd::Resolution input_resolution = rd::Resolution(INPUT_WIDTH, INPUT_HEIGHT);
  rd::Resolution convert_resolution =
      rd::Resolution(CONVERT_WIDTH, CONVERT_HEIGHT);
  rd::Format format = rd::Format::RGB;
   rd::Format input_format = rd::Format::YUY2;
   rd::Format input_format = rd::Format::YUY2;


Line 212: Line 191:
   std::shared_ptr<rd::io::IBuffer> output_final =
   std::shared_ptr<rd::io::IBuffer> output_final =
       backend_cpu->getBuffer(input_resolution, input_format);
       backend_cpu->getBuffer(input_resolution, input_format);
  std::shared_ptr<rd::io::IBuffer> input_convert =
      backend->getBuffer(convert_resolution, format);
   std::shared_ptr<rd::io::IBuffer> output =
   std::shared_ptr<rd::io::IBuffer> output =
       backend->getBuffer(input_resolution, input_format);
       backend->getBuffer(input_resolution, input_format);
Line 219: Line 196:
       backend->getBuffer(input_resolution, input_format);
       backend->getBuffer(input_resolution, input_format);


  /*Copy input buffer to GPU*/
   input_gpu->copyFromHost(input);
   input_gpu->copyFromHost(input);
  /* Preprocess image to be accepted by the face recognition model */
 
  algorithm->convert(input_gpu, input_convert);
   /* Detect Faces */
   /* Detect Faces */
   std::vector<rd::Rectangle> faces;
   std::vector<rd::Rectangle> faces;
   algorithm->detect(model, input_convert, &faces);
   algorithm->detect(model, input_gpu, &faces);
 
   /* Print out detected faces */
   /* Print out detected faces */
   std::cout << faces.size() << std::endl;
   std::cout << faces.size() << std::endl;
Line 233: Line 211:
   /* Redact detected faces */
   /* Redact detected faces */
   algorithm->redact(input_gpu, output, faces, rd::RedactionAlgorithm::BLURRING);
   algorithm->redact(input_gpu, output, faces, rd::RedactionAlgorithm::BLURRING);
   /* Download buffer to CPU memory */
 
   /* Download buffer back to CPU memory */
   output->copyToHost(output_final);
   output->copyToHost(output_final);
   /* Save redacted image */
   /* Save redacted image */
   save_buffer(output_final, "output_final");
   save_buffer(output_final, "output_final");
Cookies help us deliver our services. By using our services, you agree to our use of cookies.