Skip to content
Snippets Groups Projects
Commit f8180b05 authored by RIBEIRO-LUSTOSA Leandro's avatar RIBEIRO-LUSTOSA Leandro
Browse files

added UDP conexion between tello-vision and Simulink

parent 54778197
No related branches found
No related tags found
No related merge requests found
#include "opencv2/opencv.hpp"
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#define PORT 11112
#define MAXLINE 1024
using namespace cv;
int main(int argc, char** argv) {
int sockfd;
char buffer[MAXLINE];
char hello[] = "x:12;y:34;";
struct sockaddr_in servaddr, cliaddr;
// Creating socket file descriptor
if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
perror("socket creation failed");
exit(EXIT_FAILURE);
}
memset(&servaddr, 0, sizeof(servaddr));
memset(&cliaddr, 0, sizeof(cliaddr));
// Filling server information
servaddr.sin_family = AF_INET; // IPv4
servaddr.sin_addr.s_addr = INADDR_ANY;
servaddr.sin_port = htons(PORT+1);
// Filling cliaddr information
cliaddr.sin_family = AF_INET; // IPv4
cliaddr.sin_addr.s_addr = INADDR_ANY;
cliaddr.sin_port = htons(PORT);
// Bind the socket with the server address
if ( bind(sockfd, (const struct sockaddr *)&servaddr,
sizeof(servaddr)) < 0 ) {
perror("bind failed");
exit(EXIT_FAILURE);
}
int len, n;
Mat frame;
VideoCapture cap("udp://127.0.0.1:11111",CAP_FFMPEG);
......@@ -17,6 +61,10 @@ int main(int argc, char** argv) {
imshow("tello vision", frame);
sendto(sockfd, (const char *)hello, strlen(hello),
0, (const struct sockaddr *) &cliaddr,
sizeof(cliaddr));
if ( frame.empty() ) break; // end of video stream
if( waitKey(10) == 27 ) break; // stop capturing by pressing ESC
......
No preview for this file type
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment