google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
27.61k stars 5.17k forks source link

examples pose_tracking_cpu in some frame would stop in "if (!poller_mark.Next(&packet_mark))" #3138

Closed fatarcher closed 1 year ago

fatarcher commented 2 years ago

In same video ,for demo ,it would work out.But I want get pose_landmark, add "constexpr char kOutputStream_point[] = "pose_landmarks";"

" ASSIGN_OR_RETURN(mediapipe::OutputStreamPoller poller_mark, graph.AddOutputStreamPoller(kOutputStream_point));" mediapipe::Packet packet,packet_mark;

"if (!poller_mark.Next(&packet_mark)) break;" in demo. in some frame ,it would stop in "if (!poller_mark.Next(&packet_mark)) break;" and ,it never break, just stop.

sureshdagooglecom commented 2 years ago

Hi @fatarcher , could you please elaborate this issue to investigate further.

fatarcher commented 2 years ago

`absl::Status RunMPPGraph() { std::string calculator_graph_config_contents; MP_RETURN_IF_ERROR(mediapipe::file::GetContents( absl::GetFlag(FLAGS_calculator_graph_config_file), &calculator_graph_config_contents)); LOG(INFO) << "Get calculator graph config contents: " << calculator_graph_config_contents; mediapipe::CalculatorGraphConfig config = mediapipe::ParseTextProtoOrDie( calculator_graph_config_contents);

LOG(INFO) << "Initialize the calculator graph."; mediapipe::CalculatorGraph graph; MP_RETURN_IF_ERROR(graph.Initialize(config));

LOG(INFO) << "Initialize the camera or load the video."; cv::VideoCapture capture; const bool load_video = !absl::GetFlag(FLAGS_input_video_path).empty(); if (load_video) { capture.open(absl::GetFlag(FLAGS_input_video_path)); } else { capture.open(0); } RET_CHECK(capture.isOpened());

cv::VideoWriter writer; const bool save_video = !absl::GetFlag(FLAGS_output_video_path).empty(); if (!save_video) { cv::namedWindow(kWindowName, /flags=WINDOW_AUTOSIZE/ 1);

if (CV_MAJOR_VERSION >= 3) && (CV_MINOR_VERSION >= 2)

capture.set(cv::CAP_PROP_FRAME_WIDTH, 640);
capture.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
capture.set(cv::CAP_PROP_FPS, 30);

endif

}

LOG(INFO) << "Start running the calculator graph."; ASSIGN_OR_RETURN(mediapipe::OutputStreamPoller poller_mark, graph.AddOutputStreamPoller(kOutputStream_point)); ASSIGN_OR_RETURN(mediapipe::OutputStreamPoller poller, graph.AddOutputStreamPoller(kOutputStream)); MP_RETURN_IF_ERROR(graph.StartRun({})); int fream_cnt = 0; LOG(INFO) << "Start grabbing and processing frames."; bool grab_frames = true; while (grab_frames) { cv::Mat camera_frame_raw; capture >> camera_frame_raw; if (camera_frame_raw.empty()) { if (!load_video) { LOG(INFO) << "Ignore empty frames from camera."; continue; } LOG(INFO) << "Empty frame, end of video reached."; break; } cv::Mat camera_frame; cv::cvtColor(camera_frame_raw, camera_frame, cv::COLOR_BGR2RGB); if (!load_video) { cv::flip(camera_frame, camera_frame, /flipcode=HORIZONTAL/ 1); } LOG(INFO) << "fream_cnt" << fream_cnt; auto input_frame = absl::make_unique( mediapipe::ImageFormat::SRGB, camera_frame.cols, camera_frame.rows, mediapipe::ImageFrame::kDefaultAlignmentBoundary); cv::Mat input_frame_mat = mediapipe::formats::MatView(input_frame.get()); camera_frame.copyTo(input_frame_mat); //imwrite("/data/ft_local/work/ft_local/test/pic/"+std::to_string(fream_cnt)+".jpg",camera_frame); //fream_cnt ++; //if(fream_cnt == 24) continue; size_t frame_timestamp_us = (double)cv::getTickCount() / (double)cv::getTickFrequency() * 1e6; MP_RETURN_IF_ERROR(graph.AddPacketToInputStream( kInputStream, mediapipe::Adopt(input_frame.release()) .At(mediapipe::Timestamp(frame_timestamp_us))));

mediapipe::Packet packet,packet_mark;
if (!poller.Next(&packet)) break;
auto& output_frame = packet.Get<mediapipe::ImageFrame>();
if (!poller_mark.Next(&packet_mark)) break;
auto& pose_landmark = packet_mark.Get<mediapipe::NormalizedLandmarkList>();
cv::Mat output_frame_mat = mediapipe::formats::MatView(&output_frame);
cv::cvtColor(output_frame_mat, output_frame_mat, cv::COLOR_RGB2BGR);
//imwrite("/data/ft_local/work/ft_local/test/pic/"+std::to_string(fream_cnt)+".jpg",camera_frame);
fream_cnt ++;
if (save_video) {
  if (!writer.isOpened()) {
    LOG(INFO) << "Prepare video writer.";
    writer.open(absl::GetFlag(FLAGS_output_video_path),
                mediapipe::fourcc('a', 'v', 'c', '1'),  // .mp4
                capture.get(cv::CAP_PROP_FPS), output_frame_mat.size());
    RET_CHECK(writer.isOpened());
  }
  writer.write(output_frame_mat);
} else {
  cv::imshow(kWindowName, output_frame_mat);
  const int pressed_key = cv::waitKey(5);
  if (pressed_key >= 0 && pressed_key != 255) grab_frames = false;
}

}

LOG(INFO) << "Shutting down."; if (writer.isOpened()) writer.release(); MP_RETURN_IF_ERROR(graph.CloseInputStream(kInputStream)); return graph.WaitUntilDone(); }`

here is my code ,in my test video it stop in "if (!poller_mark.Next(&packet_mark)) break;" and fream_cnt is 23 or 56 or 156 or some fream.But in demo this video is ok.`

fatarcher commented 2 years ago

what else can I provide.

google-ml-butler[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

google-ml-butler[bot] commented 2 years ago

Closing as stale. Please reopen if you'd like to work on this further.

google-ml-butler[bot] commented 2 years ago

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] commented 2 years ago

Closing as stale. Please reopen if you'd like to work on this further.

google-ml-butler[bot] commented 2 years ago

Are you satisfied with the resolution of your issue? Yes No

sureshdagooglecom commented 2 years ago

Hi @ivan-grishchenko , Could you please have look on this issue.

ghost commented 2 years ago

I have the same problem

fishboyzyf commented 1 year ago

mediapipe::StatusOrPoller faceLandmarks = m_Graph.AddOutputStreamPoller(m_OutputStreamName,true);

// 5 FaceLandmarks
mediapipe::Packet faceLandmarksPacket;
if (!m_pFaceLandmarksPoller->Next(&faceLandmarksPacket)) {
    return absl::InvalidArgumentError("no next packet");
}
if (faceLandmarksPacket.IsEmpty()) {
    return absl::InvalidArgumentError("no next packet");
}
kuaashish commented 1 year ago

Hello @fatarcher, We are upgrading the MediaPipe Legacy Solutions to new MediaPipe solutions However, the libraries, documentation, and source code for all the MediapPipe Legacy Solutions will continue to be available in our GitHub repository and through library distribution services, such as Maven and NPM.

You can continue to use those legacy solutions in your applications if you choose. Though, we would request you to check new MediaPipe solutions which can help you more easily build and customize ML solutions for your applications. These new solutions will provide a superset of capabilities available in the legacy solutions. Thank you

github-actions[bot] commented 1 year ago

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

github-actions[bot] commented 1 year ago

This issue was closed due to lack of activity after being marked stale for past 7 days.

google-ml-butler[bot] commented 1 year ago

Are you satisfied with the resolution of your issue? Yes No