add G1 camera

This commit is contained in:
AiYangSky 2023-12-20 18:55:51 +08:00
parent a0d3e258d9
commit 173acc7036
3 changed files with 109 additions and 10 deletions

View File

@ -0,0 +1,103 @@
/*
* @Description:
* @Author: L LC @amov
* @Date: 2023-12-19 18:30:17
* @LastEditors: L LC @amov
* @LastEditTime: 2023-12-20 18:50:45
* @FilePath: /SpireCV/video_io/driver/sv_camera_G1.cpp
*/
#include "../sv_camera_privately.h"
#include <fstream>
#include <map>
#include <iterator>
class sv_camera_G1 : public sv_p::CameraBase
{
private:
std::string _ip;
uint16_t _port = 554;
bool setStream(const std::string &ip, uint16_t port);
sv::CameraType getType(void) { return sv::CameraType::G1; }
std::string getName(void) { return _ip; }
bool open(void);
public:
sv_camera_G1();
~sv_camera_G1();
};
bool sv_camera_G1::setStream(const std::string &ip, uint16_t port)
{
bool ret = false;
if (!this->cap.isOpened())
{
this->_ip = ip;
ret = true;
}
return ret;
}
// 合法的输入尺寸列表
const static std::vector<uint32_t, uint32_t> imageSizeList[3] =
{
{1520, 2704},
{1080, 1920},
{720, 1280}};
const static uint32_t imageHList[3] = {1520, 1080, 720};
const static uint32_t imageWList[3] = {2704, 1920, 1280};
// 无论如何都用gst打开 因此安装的时候必须安装gst
bool sv_camera_G1::open(void)
{
std::ostringstream pipeline;
pipeline << "rtspsrc location = rtsp://" << this->_ip << ":"
<< this->_port << "/H264?W=";
// 判断尺寸是否合法 不合法则找最高画质进行缩放
uint8_t i;
for (i = 0; i < 3; i++)
{
if (imageHList[i] <= this->getH())
{
if (imageWList[i] <= this->getW())
{
break;
}
}
}
// 在范围内
if (i < 3)
{
pipeline << imageWList[i] << "&H=" << imageHList[i];
}
else
{
pipeline << imageWList[2] << "&H=" << imageHList[2];
}
pipeline << "&FPS=" << this->getExpectFps() << "&BR=4000000 latency=100 "
<< "! application/x-rtp,media=video ! rtph264depay ! parsebin ! ";
#ifdef PLATFORM_JETSON
pipeline << "nvv4l2decoder enable-max-performancegst=1 \
! nvvidconv ! video/x-raw,format=(string)BGRx"
<< ",width=(int)" << this->getW()
<< ",height=(int)" << this->getH();
#else
pipeline << "avdec_h264 ! videoscale ! video/x-raw"
<< ",width=(int)" << this->getW()
<< ",height=(int)" << this->getH();
#endif
pipeline << " ! videoconvert ! video/x-raw,format=(string)BGR ! appsink sync=false";
this->cap.open(pipeline.str(), cv::CAP_GSTREAMER);
// 开启读取线程
std::thread readLoop(&CameraBase::readThread, this);
this->readThreadHandle = readLoop.native_handle();
readLoop.detach();
}

View File

@ -25,7 +25,7 @@ void sv_p::CameraBase::readThread(void)
{
this->cap.release();
// 抛出异常 并返回
throw std::runtime_error("SpireCV (101) Camera has offline, check CAMERA!");
// throw std::runtime_error("SpireCV (101) Camera has offline, check CAMERA!");
return;
}
}
@ -98,10 +98,6 @@ void sv_p::CameraBase::setExposure(double exposure)
}
}
bool sv_p::CameraBase::open(void)
{
}
bool sv_p::CameraBase::read(cv::Mat &image)
{
bool ret = false;
@ -111,6 +107,7 @@ bool sv_p::CameraBase::read(cv::Mat &image)
// 获取图像
this->imageBuff.copyTo(image);
ret = true;
isGot = false;
}
return ret;
}

View File

@ -29,17 +29,16 @@ private:
// 内部状态
double fpsCurr = -1;
bool isGot = false;
public:
// 内部变量
cv::Mat imageBuff;
cv::VideoCapture cap;
std::mutex frameMutex;
std::condition_variable_any frameEmpty;
std::thread::native_handle_type readThreadHandle = 0;
cv::VideoCapture cap;
// 获取图像的线程 在这个线程中查询、提取图像
virtual void readThread(void);
public:
// 属性设置的接口
virtual void setWH(int width, int height);
// 基本属性 至少实现1个
@ -71,7 +70,7 @@ public:
double getExposure(void) { return _exposure; }
// 功能接口函数
virtual bool open(void);
virtual bool open(void) = 0;
virtual bool read(cv::Mat &image);
virtual bool readNoBlock(cv::Mat &image);
virtual void release(void);