You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Software_Architecture/mediamodule/examples/example_getimagetrans.cc

64 lines
2.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* @file example_getRectFrame.cc
* @brief This file is part of UnitreeCameraSDK.
* @details This example that how to Transmission picture
* @author SunMingzhe
* @date 2021.12.07
* @version 1.1.0
* @copyright Copyright (c) 2020-2021, Hangzhou Yushu Technology Stock CO.LTD. All Rights Reserved.
*/
/*
接收端:
方法概述采用定向udp方法接收图片在应用其之前需要先发送图片例子:example_putImagetrans.cc
端口9201~9205分别对应前方下巴腹部
本机ip需要是192.168.123.IpLastSegmentIpLastSegment被设置在发送端cofigure yaml-
*/
/*
listener
Introduction: This program uses directed UDP methods to get pictures,whitch requires sending pictures on other programs. for example:example_putImagetrans.cc
port:9201~9205 -> Front,chin,left,right,abdomen
local ip must be set to 192.168.123.IpLastSegment and IpLastSegment musb be set in cofigure yaml
*/
/*
local ip config
ip 192.168.123.IpLastSegment
netmask 255.255.255.0
gateway 192.168.123.1
*/
#include <opencv2/opencv.hpp>
#include <iostream>
int main(int argc,char** argv)
{
std::string IpLastSegment = "161";
int cam = 1;
if (argc>=2)
cam = std::atoi(argv[1]);
std::string udpstrPrevData = "udpsrc address=192.168.123."+ IpLastSegment + " port=";
//端口:前方,下巴,左,右,腹部
std::array<int,5> udpPORT = std::array<int, 5>{9201, 9202, 9203, 9204, 9205};
//std::string udpstrBehindData = " ! application/x-rtp,media=video,encoding-name=H264 ! rtph264depay ! h264parse ! omxh264dec ! videoconvert ! appsink";
std::string udpstrBehindData = " ! application/x-rtp,media=video,encoding-name=H264 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! appsink";
std::string udpSendIntegratedPipe = udpstrPrevData + std::to_string(udpPORT[cam-1]) + udpstrBehindData;
std::cout<<"udpSendIntegratedPipe:"<<udpSendIntegratedPipe<<std::endl;
cv::VideoCapture cap(udpSendIntegratedPipe);
if(!cap.isOpened())
return 0 ;
cv::Mat frame;
while(1)
{
cap >> frame;
if(frame.empty())
break;
imshow("video", frame);
cv::waitKey(20);
}
cap.release();//释放资源
return 0;
}