56 lines
1.5 KiB
C++
56 lines
1.5 KiB
C++
#include <opencv2/highgui.hpp>
|
|
#include <opencv2/core/mat.hpp>
|
|
#include <opencv2/imgproc.hpp>
|
|
#include <cstring>
|
|
#include <iostream>
|
|
#include <netinet/in.h>
|
|
#include <sys/socket.h>
|
|
#include <unistd.h>
|
|
#include "transfer.h"
|
|
#include "logging.h"
|
|
#include <boost/asio.hpp>
|
|
|
|
using namespace std;
|
|
using boost::asio::ip::tcp;
|
|
|
|
int main() {
|
|
try {
|
|
boost::asio::io_context io_context;
|
|
// creating socket
|
|
|
|
tcp::acceptor acceptor(io_context, tcp::endpoint(tcp::v4(), 8080));
|
|
|
|
tcp::socket socket(io_context);
|
|
|
|
info("Ready to accept connections.");
|
|
|
|
// accepting connection request
|
|
acceptor.accept(socket);
|
|
info("Client connected.");
|
|
|
|
// TODO: handle multiple images
|
|
cv::Mat image = cv::Mat::zeros(cv::Size(640, 480), CV_8UC3);
|
|
|
|
bool running = true;
|
|
// TODO: make this asynchronous. probably do that in tandem with setting up networking
|
|
while (running) {
|
|
// receive data
|
|
vector<uchar> buffer;
|
|
trace("Receiving image");
|
|
int latency = recvImage(socket, buffer);
|
|
|
|
trace("Applying new data to image");
|
|
applyImage(image, &buffer);
|
|
|
|
cv::putText(image, to_string(latency), cv::Point(0, 480), cv::FONT_HERSHEY_PLAIN, 1, cv::Scalar(255, 0, 0), 1, cv::LINE_AA);
|
|
|
|
trace("Displaying image");
|
|
imshow("image", image);
|
|
running = cv::waitKey(30) != 27;
|
|
}
|
|
}
|
|
catch (std::exception& e) {
|
|
error(e.what());
|
|
}
|
|
return 0;
|
|
} |