add RTSP, VIDEO to sv::CameraType

This commit is contained in:
jario 2023-12-25 15:00:35 +08:00
parent c20cd83f1c
commit 182c2d9f0b
3 changed files with 44 additions and 1 deletions

View File

@ -327,7 +327,7 @@ protected:
};
enum class CameraType {NONE, WEBCAM, V4L2CAM, G1, Q10, MIPI, GX40};
enum class CameraType {NONE, WEBCAM, V4L2CAM, MIPI, RTSP, VIDEO, G1, Q10, GX40};
class CameraBase {
public:
@ -351,6 +351,8 @@ public:
void setWH(int width, int height);
void setFps(int fps);
void setIp(std::string ip);
void setRtspUrl(std::string rtsp_url);
void setVideoPath(std::string video_path);
void setPort(int port);
void setBrightness(double brightness);
void setContrast(double contrast);
@ -373,6 +375,8 @@ protected:
int _height;
int _fps;
std::string _ip;
std::string _rtsp_url;
std::string _video_path;
int _port;
double _brightness;
double _contrast;

View File

@ -1080,6 +1080,14 @@ void CameraBase::setIp(std::string ip)
{
this->_ip = ip;
}
void CameraBase::setRtspUrl(std::string rtsp_url)
{
this->_rtsp_url = rtsp_url;
}
void CameraBase::setVideoPath(std::string video_path)
{
this->_video_path = video_path;
}
void CameraBase::setPort(int port)
{
this->_port = port;

View File

@ -19,6 +19,7 @@ void Camera::openImpl()
if (this->_type == CameraType::V4L2CAM)
{
this->_cap.open(this->_camera_id, cv::CAP_V4L2);
// this->_cap.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('Y', 'U', 'Y', 'V'));
}
if (this->_type == CameraType::WEBCAM)
{
@ -127,6 +128,36 @@ void Camera::openImpl()
sprintf(pipe, "nvarguscamerasrc sensor-id=%d ! video/x-raw(memory:NVMM), width=(int)%d, height=(int)%d, format=(string)NV12, framerate=(fraction)%d/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink", this->_camera_id, this->_width, this->_height, this->_fps, this->_width, this->_height);
this->_cap.open(pipe, cv::CAP_GSTREAMER);
}
else if (this->_type == CameraType::RTSP)
{
char pipe[512];
if (this->_width <= 0 || this->_height <= 0)
{
this->_width = 1280;
this->_height = 720;
}
if (this->_port <= 0)
{
this->_port = 554;
}
if (this->_fps <= 0)
{
this->_fps = 30;
}
#ifdef PLATFORM_X86_CUDA
sprintf(pipe, "%s?W=%d&H=%d&FPS=%d", this->_rtsp_url.c_str(), this->_width, this->_height, this->_fps);
this->_cap.open(pipe);
#endif
#ifdef PLATFORM_JETSON
sprintf(pipe, "rtspsrc location=%s?W=%d&H=%d&FPS=%d latency=100 ! application/x-rtp,media=video ! rtph264depay ! parsebin ! nvv4l2decoder enable-max-performancegst=1 ! nvvidconv ! video/x-raw,format=(string)BGRx ! videoconvert ! appsink sync=false", this->_rtsp_url.c_str(), this->_width, this->_height, this->_fps);
this->_cap.open(pipe, cv::CAP_GSTREAMER);
#endif
}
else if (this->_type == CameraType::VIDEO)
{
this->_cap.open(this->_video_path);
}
}
}