feat: 发送rgb格式

This commit is contained in:
bmy
2024-05-27 16:00:05 +08:00
parent d5c427258a
commit 22734fdf13
2 changed files with 13 additions and 4 deletions

View File

@@ -2,9 +2,12 @@
#include <vector>
#include <thread>
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <zmq.hpp>
#include "logc/log.h"
#include <unistd.h>
capture::capture(int camera_index, int zmq_port, int width_set, int height_set, int fps_set)
{
@@ -34,7 +37,8 @@ capture::capture(int camera_index, int zmq_port, int width_set, int height_set,
context = new zmq::context_t(1);
socket = new zmq::socket_t(*context, ZMQ_PUB);
int hwm = 10;
socket->setsockopt(ZMQ_SNDHWM, &hwm, sizeof(hwm));
char zmq_bind_port[10] = {0};
sprintf(zmq_bind_port, "%d", port);
strcat(zmq_bind_addr, zmq_bind_port);
@@ -57,6 +61,7 @@ void capture::start(void)
void capture::run(void)
{
cv::Mat dst;
while (1)
{
*cap >> frame;
@@ -72,11 +77,14 @@ void capture::run(void)
frame = frame.clone().reshape(1, frame.total());
}
cv::cvtColor(frame, dst, cv::COLOR_BGR2RGB);
// cv::imshow(zmq_bind_addr, frame);
// 将帧编码后发送
std::vector<uchar> buff;
cv::imencode(".jpg", frame, buff);
std::vector<uchar>
buff;
cv::imencode(".jpg", dst, buff);
zmq::message_t message(buff.size());
memcpy(message.data(), buff.data(), buff.size());
socket->send(message, zmq::send_flags::none);
@@ -95,6 +103,7 @@ void capture::run(void)
// socket->send(frame_msg, zmq::send_flags::none);
// 在这里添加一些延迟,以控制帧率
cv::waitKey(1);
// usleep(20000);
}
}

View File

@@ -48,7 +48,7 @@ int main(int argc, char **argv)
capture cap2(server_2_index.u.i, server_2_port.u.i);
cap0.start();
// cap1.start();
cap1.start();
cap2.start();
while (1)