无标题

Posted 热爱生活的技术控

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无标题相关的知识,希望对你有一定的参考价值。

#include <stdio.h>

#include <mediapipe/framework/calculator_framework.h>
#include <mediapipe/framework/formats/image_frame.h>
#include <mediapipe/framework/formats/image_frame_opencv.h>
#include <mediapipe/framework/port/opencv_core_inc.h>
#include <mediapipe/framework/port/opencv_imgproc_inc.h>
#include <mediapipe/framework/port/parse_text_proto.h>
#include <mediapipe/framework/port/status.h>
#include <mediapipe/solutions/drawing_utils.h>
#include <mediapipe/solutions/face_mesh.h>
#include <mediapipe/util/tracking/region_flow.h>

using mediapipe::CalculatorGraphConfig;
using mediapipe::ParseTextProtoOrDie;
using mediapipe::face_mesh::FaceMesh;
using mediapipe::solutions::drawing_utils::DrawingSpec;
using mediapipe::solutions::drawing_utils::DrawingStyle;

int main()
// Initialize CalculatorGraph config
CalculatorGraphConfig config =
ParseTextProtoOrDie(R"(
node
calculator: “FaceMeshCalculator”
input_stream: “VIDEO:video_frames”
output_stream: “FACE_MESH:face_mesh”
options
[mediapipe.FaceMeshCalculatorOptions.ext]
min_detection_confidence: 0.5
min_tracking_confidence: 0.5



node
calculator: “VideoToImageCalculator”
input_stream: “VIDEO:video_frames”
output_stream: “IMAGE:image_frame”

node
calculator: “DrawFaceMeshCalculator”
input_stream: “IMAGE:image_frame”
input_stream: “FACE_MESH:face_mesh”
output_stream: “IMAGE:image_frame_with_mesh”
options
[mediapipe.DrawFaceMeshCalculatorOptions.ext]
landmark_drawing_spec
thickness: 1
circle_radius: 1

tesselation_style: SOLID



)");

// Open video capture
cv::VideoCapture cap(0);
cv::Mat image;

// Initialize FaceMesh
FaceMesh face_mesh;
face_mesh.Initialize();

// Run the Calculator graph
mediapipe::CalculatorGraph graph;
MP_RETURN_IF_ERROR(graph.Initialize(config));
MP_RETURN_IF_ERROR(graph.StartRun(“VIDEO:video_frames”, cap));

// Main loop
while (cap.read(image))
// Flip the image horizontally and convert the color space from BGR to RGB
image = cv::cvtColor(cv::flip(image, 1), cv::COLOR_BGR2RGB);

// Detect the face landmarks
auto results = face_mesh.Process(image);

// Convert back to the BGR color space
image = cv::cvtColor(image, cv::COLOR_RGB2BGR);

// Draw the face mesh annotations on the image
if (results.multi_face_landmarks.size() > 0) 
  DrawingSpec spec;
  spec.thickness = 1;
  spec.circle_radius = 1;
  mp::solutions::drawing_utils::DrawLandmarks(
      image, results.multi_face_landmarks,
      mp::face_mesh::FACEMESH_TESSELATION, spec,
      mp::solutions::drawing_styles::GetDefaultFaceMeshTesselationStyle());


// Display the image
cv::imshow("MediaPipe FaceMesh", image);

// Terminate the process
if (cv::waitKey(5) & 0xFF == 27) 
  break;

// Close the Calculator graph
MP_RETURN_IF_ERROR(graph.CloseInputStream(“VIDEO:video_frames”));
MP_RETURN_IF_ERROR(graph.WaitUntilDone());

以上是关于无标题的主要内容,如果未能解决你的问题,请参考以下文章

计算机视觉基于Python—OpenCV的手势识别详解

计算机视觉基于Python—OpenCV的手势识别详解

人工智能计算机视觉之OpenCV学习详解一

计算机视觉-OpenCV入门讲解

计算机视觉OpenCV-图像直方图

OpenCV+TensorFlow 入门人工智能图像处理