SpireCV/video_io/driver/sv_camera_MC1.cpp

79 lines
1.7 KiB
C++

/*
* @Description:
* @Author: L LC @amov
* @Date: 2023-12-19 18:30:17
* @LastEditors: L LC @amov
* @LastEditTime: 2023-12-21 17:57:07
* @FilePath: /SpireCV/video_io/driver/sv_camera_MC1.cpp
*/
#include "sv_camera_privately.h"
#include <fstream>
class sv_camera_MC1 : public sv_p::CameraBase
{
private:
int _index = -2;
public:
bool setIndex(int index);
sv::CameraType getType(void) { return sv::CameraType::MC1; }
bool open(void);
sv_camera_MC1(int timeOut);
~sv_camera_MC1();
static CameraBase *creat(int timeOut)
{
#ifdef PLATFORM_JETSON
return new sv_camera_MC1(timeOut);
#else
throw std::runtime_error("SpireCV (101) Camera not supported except allspark");
return nullptr;
#endif
}
};
sv_camera_MC1::sv_camera_MC1(int timeOut) : sv_p::CameraBase(timeOut)
{
}
bool sv_camera_MC1::setIndex(int index)
{
bool ret = false;
if (!this->cap.isOpened())
{
this->_index = index;
ret = true;
}
return ret;
}
// 普通的mipi相机 采用 v4l2 框架打开
bool sv_camera_MC1::open(void)
{
bool ret = false;
std::ostringstream pipeline;
pipeline << "nvarguscamerasrc sensor-id=" << this->_index;
pipeline << " ! video/x-raw,video/x-raw(memory:NVMM),"
<< "width=(int)" << this->getW()
<< "height=(int)" << this->getH()
<< "framerate=" << this->getExpectFps() << "/1 !"
<< " nvvidconv flip-method=0 ! video/x-raw,format=(string)BGRx !"
<< " videoconvert ! video/x-raw, format=(string)BGR ! appsink";
if (this->cap.open(pipeline.str(), cv::CAP_GSTREAMER))
{
// 开启读取线程
std::thread readLoop(&CameraBase::readThread, this);
this->readThreadHandle = readLoop.native_handle();
readLoop.detach();
ret = true;
}
return ret;
}