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