HW140701 / GoogleMediapipePackageDll

package google mediapipe hand and holistic tracking into a dynamic link library
Apache License 2.0
169 stars 47 forks source link

opencv 声明的变量经常会报错,未声明的变量, 以及图像送入mediapipe 推理错误 #16

Closed yunshangyue71 closed 2 years ago

yunshangyue71 commented 2 years ago
// 获取当前距离1970的微秒时间
// size_t frame_timestamp_us =
//      (double)cv::getTickCount() / (double)cv::getTickFrequency() * 1e6;

std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds> tpMicro
    = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now());
size_t frame_timestamp_us = tpMicro.time_since_epoch().count();

作者本来用的是我注释掉的,但是我编译的时候就会报错,未声明变量

我用作者注释掉的代码作为时间戳,图片信息一直不能送进去, 图片的宽高这个信息我已经调整了。 MP_RETURN_IF_ERROR(m_Graph.AddPacketToInputStream( m_Video_InputStreamName, mediapipe::Adopt(input_frame.release()).At(mediapipe::Timestamp(frame_timestamp_us)))); 再次打扰,多谢了

yunshangyue71 commented 2 years ago

/----- 1 构造cv::Mat对象 -----/ cv::Mat camera_frame(cv::Size(image_width, image_height), CV_8UC3, (uchar*)image_data);

// BGR转RGB
cv::Mat camera_frame_RGB;
cv::cvtColor(camera_frame, camera_frame_RGB, cv::COLOR_BGR2RGB);

// 水平翻转
cv::flip(camera_frame_RGB, camera_frame_RGB, 1);

std::cout << "cv::Mat object done" << std::endl;

/*----- 2 将OpenCV Mat转换为ImageFrame -----*/
auto input_frame = absl::make_unique<mediapipe::ImageFrame>(
    mediapipe::ImageFormat::SRGB, camera_frame_RGB.cols, camera_frame_RGB.rows,
    mediapipe::ImageFrame::kDefaultAlignmentBoundary);
//camera_frame_RGB.copyTo(mediapipe::formats::MatView(input_frame.get()));
cv::Mat input_frame_mat = mediapipe::formats::MatView(input_frame.get());
camera_frame_RGB.copyTo(input_frame_mat);

std::cout << "OpenCV Mat --> ImageFrame " << std::endl;

/*----- 3 发送图片到图中推理 -----*/
// 获取当前距离1970的微秒时间
// size_t frame_timestamp_us =
//      (double)cv::getTickCount() / (double)cv::getTickFrequency() * 1e6;

std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds> tpMicro
    = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now());
size_t frame_timestamp_us = tpMicro.time_since_epoch().count();

MP_RETURN_IF_ERROR(m_Graph.AddPacketToInputStream(
    m_Video_InputStreamName, mediapipe::Adopt(input_frame.release()).At(mediapipe::Timestamp(frame_timestamp_us))));

std::cout << "Send image to inference done" << std::endl;

步骤1、2 能打印出来log , 步骤3 的log 打印不出来