SpireCV/video_io/driver/sv_camera_V4L2s.cpp

150 lines
2.8 KiB
C++

/*
* @Description:
* @Author: L LC @amov
* @Date: 2023-12-21 10:45:50
* @LastEditors: L LC @amov
* @LastEditTime: 2023-12-21 17:57:30
* @FilePath: /SpireCV/video_io/driver/sv_camera_V4L2s.cpp
*/
#include "sv_camera_privately.h"
class sv_camera_V4L2 : public sv_p::CameraBase
{
private:
int _index = -1;
std::string _name = "\0";
public:
bool setName(const std::string &name);
bool setIndex(int index);
virtual sv::CameraType getType(void) { return sv::CameraType::V4L2CAM; }
std::string getName(void) { return this->_name; }
bool open(void);
sv_camera_V4L2(int timeOut);
~sv_camera_V4L2();
static CameraBase *creat(int timeOut)
{
return new sv_camera_V4L2(timeOut);
}
};
sv_camera_V4L2::sv_camera_V4L2(int timeOut) : sv_p::CameraBase(timeOut)
{
}
bool sv_camera_V4L2::setName(const std::string &name)
{
bool ret = false;
if (!this->cap.isOpened())
{
this->_name = name;
ret = true;
}
return ret;
}
bool sv_camera_V4L2::setIndex(int index)
{
bool ret = false;
if (!this->cap.isOpened())
{
this->_index = index;
ret = true;
}
return ret;
}
bool sv_camera_V4L2::open(void)
{
bool ret = false;
if (this->_index >= 0)
{
ret = this->cap.open(this->_index, cv::CAP_V4L2);
}
if (!ret)
{
if (this->_name != "\0")
{
ret = this->cap.open(this->_name, cv::CAP_V4L2);
}
}
if (ret)
{
// 设置属性
this->setFps(this->getExpectFps());
this->setBrightness(this->getBrightness());
this->setContrast(this->getContrast());
this->setSaturation(this->getSaturation());
this->setHue(this->getHue());
this->setExposure(this->getExposure());
// 开启读取线程
std::thread readLoop(&CameraBase::readThread, this);
this->readThreadHandle = readLoop.native_handle();
readLoop.detach();
}
return ret;
}
class sv_camera_WEBCAM : public sv_camera_V4L2
{
public:
sv::CameraType getType(void) { return sv::CameraType::WEBCAM; }
sv_camera_WEBCAM(int timeOut);
~sv_camera_WEBCAM();
static CameraBase *creat(int timeOut)
{
return new sv_camera_WEBCAM(timeOut);
}
};
sv_camera_WEBCAM::sv_camera_WEBCAM(int timeOut) : sv_camera_V4L2(timeOut)
{
}
class sv_camera_Q10 : public sv_camera_V4L2
{
public:
sv::CameraType getType(void) { return sv::CameraType::Q10; }
sv_camera_Q10(int timeOut);
~sv_camera_Q10();
static CameraBase *creat(int timeOut)
{
return new sv_camera_Q10(timeOut);
}
};
sv_camera_Q10::sv_camera_Q10(int timeOut) : sv_camera_V4L2(timeOut)
{
}
class sv_camera_NONE : public sv_camera_V4L2
{
public:
sv::CameraType getType(void) { return sv::CameraType::NONE; }
sv_camera_NONE(int timeOut);
~sv_camera_NONE();
static CameraBase *creat(int timeOut)
{
return new sv_camera_NONE(timeOut);
}
};
sv_camera_NONE::sv_camera_NONE(int timeOut) : sv_camera_V4L2(timeOut)
{
}