UnitreeCameraSDK  1.0.1
unitree stereo camra apis
Classes | Public Member Functions | List of all members
StereoCamera Class Reference

this class integrate camera control and stereo vision algorithm More...

#include <StereoCameraCommon.hpp>

Inheritance diagram for StereoCamera:
Inheritance graph
[legend]

Public Member Functions

 StereoCamera (void)
 StereoCamera. More...
 
 StereoCamera (std::string fileName)
 
 StereoCamera (int deviceNode)
 
virtual ~StereoCamera ()
 StereoCamera destructor. More...
 
virtual bool isOpened (void)
 get stereo camera running status More...
 
virtual bool setLogLevel (int level)
 set stereo camera ouput log level More...
 
virtual bool setPosNumber (int posNumber)
 set stereo camera position number More...
 
virtual bool setSerialNumber (int serialNumber)
 set stereo camera serial number More...
 
virtual bool setRawFrameRate (int frameRate)
 set stereo camera FPS (Frames Per Seconds) More...
 
virtual bool setRawFrameSize (cv::Size frameSize)
 set stereo camera frame size More...
 
virtual bool setRectFrameSize (cv::Size frameSize)
 set rectification image size More...
 
virtual bool setCalibParams (std::vector< cv::Mat > paramsArray, bool flag=false)
 set stereo camera calibration parameters More...
 
virtual int getLogLevel (void) const
 get log system output level More...
 
virtual int getDeviceNode (void) const
 get camera device node More...
 
virtual int getPosNumber (void) const
 get stereo camera device node More...
 
virtual int getSerialNumber (void) const
 get stereo camera serial number More...
 
virtual float getRawFrameRate (void) const
 get stereo camera capture frame rate More...
 
virtual cv::Size getRawFrameSize (void) const
 get stereo camera frame size More...
 
virtual bool getRawFrame (cv::Mat &frame, std::chrono::microseconds &timeStamp)
 get stereo camera raw frame More...
 
virtual bool getStereoFrame (cv::Mat &left, cv::Mat &right, std::chrono::microseconds &timeStamp)
 get stereo camera left and right image More...
 
virtual bool getDepthFrame (cv::Mat &depth, bool color, std::chrono::microseconds &timeStamp)
 get stereo camera depth image More...
 
virtual bool getPointCloud (std::vector< cv::Vec3f > &pcl, std::chrono::microseconds &timeStamp)
 
virtual bool getPointCloud (std::vector< PCLType > &pcl, std::chrono::microseconds &timeStamp)
 
virtual bool getCalibParams (std::vector< cv::Mat > &paramsArray, bool flag=false)
 get stereo camera calibration paramerters More...
 
virtual bool getRectStereoFrame (cv::Mat &left, cv::Mat &right, cv::Mat &feim)
 
virtual bool getRectStereoFrame (cv::Mat &left, cv::Mat &right, cv::Mat &feim, std::chrono::microseconds &timeStamp)
 
virtual bool loadConfig (std::string fileName)
 load stereo camera config parameters More...
 
virtual bool loadCalibParams (std::string fileName)
 load stereo camera calibration params More...
 
virtual bool saveConfig (std::string fileName="stereo_camera_config.yaml")
 save stereo camera settings to config file More...
 
virtual bool saveCalibParams (std::string fileName="stereo_camera_calibparams.yaml")
 save stereo camera calibration parameters to file More...
 
virtual bool startCapture (bool udpFlag=false, bool shmFlag=false)
 start stereo camera capture thread More...
 
virtual bool startStereoCompute (void)
 start stereo camera computing disparity thread More...
 
virtual bool stopStereoCompute (void)
 stop stereo camera computing disparity thread More...
 
virtual bool stopCapture (void)
 stop stereo camera capture thread More...
 

Detailed Description

this class integrate camera control and stereo vision algorithm

this class is the base of UnitreeCameraSDK, it includes many functions, such as camera frame capturing, image rectification, disparity computation, generating point cloud and etc.

Constructor & Destructor Documentation

◆ StereoCamera()

StereoCamera::StereoCamera ( void  )

StereoCamera.

StereoCamera constructor overload.

default constructor

Parameters
[in]None
[out]None
Returns
None
Note
initialize StereoCamera object by default settings
StereoCamera *pCam = new StereoCamera(); or StereoCamera cam;

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

use camera config file to init stereo camera

Parameters
[in]fileNamecamera config file, include file path, for example: ~/test/stereoConfig.yaml
[out]None
Returns
None
Note
initialize StereoCamera object by settings from configure file
StereoCamera("path_to/config.yaml");

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

use camera device node number to init stereo camera

Parameters
[in]deviceNodecamera device node, for example: /dev/video0, camera device node: 0
[out]None
Returns
None
Note
initialize StereoCamera object by device node number
StereoCamera(0); // for /dev/video0

◆ ~StereoCamera()

StereoCamera::~StereoCamera ( )
virtual

StereoCamera destructor.

release all stereo camera resource

Parameters
[in]None
[out]None
Returns
None
Note
automatically called when StereoCamera object released

Member Function Documentation

◆ getCalibParams()

bool StereoCamera::getCalibParams ( std::vector< cv::Mat > &  paramsArray,
bool  flag = false 
)
virtual

get stereo camera calibration paramerters

calibration paramerters include: camera intrinsic matrix, camera distortion coefficient, xi(mei model), rotation matrix, translation vector, rectification image intrinsic matrix

Parameters
[in]flagdefault false, false: get left camera parameters, true: get right camera parameters.
[out]paramsArrayarrange Array element as follows: intrinsic,distortion,xi,rotation,translation,kfe
Returns
true or false, if assignment successfully return true, otherwise return false
Attention
This funtion must be called after startCapture()
Note
cam.startCapture();
std::vector<cv::Mat> paramsArray;
if(cam.getCalibParams(paramsArray)){
//do something
}

◆ getDepthFrame()

bool StereoCamera::getDepthFrame ( cv::Mat &  depth,
bool  color,
std::chrono::microseconds &  timeStamp 
)
virtual

get stereo camera depth image

Parameters
[in]colortrue: depth is color image, false:depth is gray image
[out]depthleft image
[out]timeStampframe time stamp
Returns
true or false, if depth image is not empty, return true, otherwise return false.
Attention
This funtion must be called after startCapture().
Note
cam.startCapture();
cam.startStereoCompute();
cv::Mat depth;
std::chrono::microseconds timeStamp;
if(cam.getPointCloud(depth, true, timeStamp)){
//do something
}

◆ getDeviceNode()

int StereoCamera::getDeviceNode ( void  ) const
virtual

get camera device node

Parameters
[in]None
[out]None
Returns
device node number
Note
for example: /dev/video2, device node number is 2, the return value of function is 2.
int nodeNumber = cam.getDeviceNode();

◆ getLogLevel()

int StereoCamera::getLogLevel ( void  ) const
virtual

get log system output level

Parameters
[in]None
[out]None
Returns
log level
Note
1: output runtime information, 2: output runtime infomation and debug information
int LogLevel = cam.getLogLevel();

◆ getPosNumber()

int StereoCamera::getPosNumber ( void  ) const
virtual

get stereo camera device node

Parameters
[in]None
[out]None
Returns
positon number
Note
face NO.1, chin NO.2, left NO.3, right NO.4, down NO.5
int posNum = cam.getPosNumber();

◆ getRawFrame()

bool StereoCamera::getRawFrame ( cv::Mat &  frame,
std::chrono::microseconds &  timeStamp 
)
virtual

get stereo camera raw frame

Parameters
[in]None
[out]frameraw frame, include left and right image
[out]timeStampraw frame time stamp
Returns
true or false, if frame is not empty, return true, otherwise return false.
Note
cv::Mat frame;
std::chrono::microseconds timeStamp
cam.getRawFrame(frame, timeStamp);

◆ getRawFrameRate()

float StereoCamera::getRawFrameRate ( void  ) const
virtual

get stereo camera capture frame rate

Parameters
[in]None
[out]None
Returns
current stereo camera fps.
float fps = getRawFrameRate();

◆ getRawFrameSize()

cv::Size StereoCamera::getRawFrameSize ( void  ) const
virtual

get stereo camera frame size

Parameters
[in]None
[out]None
Returns
frame size.
cv::Size fSize = cam.getRawFrameSize();

◆ getSerialNumber()

int StereoCamera::getSerialNumber ( void  ) const
virtual

get stereo camera serial number

this number is same as robot serial number

Parameters
[in]None
[out]None
Returns
robot serial number
Note
int seiralNumber = cam.getSerialNumber();

◆ getStereoFrame()

bool StereoCamera::getStereoFrame ( cv::Mat &  left,
cv::Mat &  right,
std::chrono::microseconds &  timeStamp 
)
virtual

get stereo camera left and right image

Parameters
[in]None
[out]leftleft image
[out]rightright image
[out]timeStampframe time stamp
Returns
true or false, if left and right images are not empty, return true, otherwise return false.
Attention
This funtion must be called after startCapture().
Note
cam.startCapture();
cv::Mat left, right;
std::chrono::microseconds timeStamp;
if(cam.getRawFrame(left,right, timeStamp)){
//do something
}

◆ isOpened()

bool StereoCamera::isOpened ( void  )
virtual

get stereo camera running status

detect camera is opened or closed

Parameters
[in]None
[out]None
Returns
true or false, if camera is opened return true, otherwise return false
Note
tell camera running status, it should be called after StereoCamera object initialization
if(cam.isOpened())
printf("Camera is opened!");

◆ loadCalibParams()

bool StereoCamera::loadCalibParams ( std::string  fileName)
virtual

load stereo camera calibration params

calibration paramerters include: camera intrinsic matrix, camera distortion coefficient, xi(mei model), rotation matrix, translation vector, rectification image intrinsic matrix, etc.

Parameters
[in]fileNamecalibration file name: include file path, for example: "path_to/calib.yaml"
[out]None
Returns
true or false, if load file successfully return true, otherwise return false
Attention
This funtion must be called before startCapture() and after loadConfig("xxx");
Note
cam.loadConfig("path_to/config.yaml");
cam.loadCalibParams("path_to/calib.yaml");

◆ loadConfig()

bool StereoCamera::loadConfig ( std::string  fileName)
virtual

load stereo camera config parameters

parameters include: LogLevel,Threshold,Algorithm,IpLastSegment, DeviceNode,FrameSize,RectifyFrameSize,FrameRate, etc.

Parameters
[in]fileNameconfig name: include config path, for example: "path_to/config.yaml"
[out]None
Returns
true or false, if load config file successfully return true, otherwise return false
Attention
This funtion must be called before startCapture() and after init the camera object.
Note
cam.loadConfig("path_to/config.yaml");

◆ saveCalibParams()

bool StereoCamera::saveCalibParams ( std::string  fileName = "stereo_camera_calibparams.yaml")
virtual

save stereo camera calibration parameters to file

Parameters
[in]fileNamedefault name: stereo_camera_calibparams.yaml, output file: include file path, for example: "path_to/calib.yaml"
[out]None
Returns
true or false, if save file successfully return true, otherwise return false
cam.saveConfig("stereo_camera_config.yaml");

◆ saveConfig()

bool StereoCamera::saveConfig ( std::string  fileName = "stereo_camera_config.yaml")
virtual

save stereo camera settings to config file

Parameters
[in]fileNamedefault name: stereo_camera_config.yaml, output config file: include file path, for example: "path_to/config.yaml"
[out]None
Returns
true or false, if save file successfully return true, otherwise return false
cam.saveConfig("stereo_camera_config.yaml");

◆ setCalibParams()

bool StereoCamera::setCalibParams ( std::vector< cv::Mat >  paramsArray,
bool  flag = false 
)
virtual

set stereo camera calibration parameters

calibration paramerters include: camera intrinsic matrix, camera distortion coefficient, xi(mei model), rotation matrix, translation vector, rectification image intrinsic matrix

Parameters
[in]paramsArrayarrange Array element as follows: intrinsic,distortion,xi,rotation,translation,kfe
[in]flagfalse: set left camera params, true: right camera params
[out]None
Returns
true or false, if assignment successfully return true, otherwise return false
Attention
the order of parameters should be correct
Note
std::vector<cv::Mat> leftParamsArray;
cam.setCalibParams(leftParamsArray);

◆ setLogLevel()

bool StereoCamera::setLogLevel ( int  level)
virtual

set stereo camera ouput log level

log level means that different kind of information will be output

Parameters
[in]level
[out]None
Returns
true or false, if assignment successfully return true, otherwise return false
Note
output information starts with "StereoCamera", it should be called after StereoCamera object initialization
cam.setLogLevel(2); //debug level

◆ setPosNumber()

bool StereoCamera::setPosNumber ( int  posNumber)
virtual

set stereo camera position number

position number means that the number of camera location in robot body

Parameters
[in]posNumber
[out]None
Returns
true or false, if assignment successfully return true, otherwise return false
Note
face NO.1, chin NO.2, left NO.3, right NO.4, down NO.5
cam.setPosNumber(2);

◆ setRawFrameRate()

bool StereoCamera::setRawFrameRate ( int  frameRate)
virtual

set stereo camera FPS (Frames Per Seconds)

for 1856X800 FPS:30, for 928x400 FPS:30 or 60

Parameters
[in]frameRate
[out]None
Returns
true or false, if assignment successfully return true, otherwise return false
Note

◆ setRawFrameSize()

bool StereoCamera::setRawFrameSize ( cv::Size  frameSize)
virtual

set stereo camera frame size

There are two choise: 1856X800,928x400.

Parameters
[in]frameSize
[out]None
Returns
true or false, if assignment successfully return true, otherwise return false
Attention
if do not assign frameSize, default size is 1856x800
Note
cam.setRawFrameSize(cv::Size(1856, 800));

◆ setRectFrameSize()

bool StereoCamera::setRectFrameSize ( cv::Size  frameSize)
virtual

set rectification image size

this size should keep ratio as camera raw image size, for example: raw single frame size: 928x800 rectification image size: 464x400 or 232x200

Parameters
[in]frameSize
[out]None
Returns
true or false, if assignment successfully return true, otherwise return false
Attention
rectification image size must be smaller than camera raw single image size
Note
cam.setRawFrameSize(cv::Size(464, 400));

◆ setSerialNumber()

bool StereoCamera::setSerialNumber ( int  serialNumber)
virtual

set stereo camera serial number

serial number same as robot serial number

Parameters
[in]serialNumber
[out]None
Returns
true or false, if assignment successfully return true, otherwise return false
Note

◆ startCapture()

bool StereoCamera::startCapture ( bool  udpFlag = false,
bool  shmFlag = false 
)
virtual

start stereo camera capture thread

Parameters
[in]udpFlagdefault false, true: enable using H264 encode camera frame and send it by gstream udp command
[in]shmFlagdefault false, true: enable using share memory to share camera frame
[out]None
Returns
true or false, if create capture thread successfully return true, otherwise return false
Note
gstreamer send command: "appsrc ! videoconvert ! omxh264enc ! video/x-h264, stream-format=byte-stream ! rtph264pay ! udpsink host=192.168.123.SEG port=hostPort". SEG is last segment of your recieve board IP, its range from 2~254,for example: 13, host=192.168.123.13. hostPort is defined by the result of adding camera position number and 9000, for example: camera positon number is 5, port=9005. share memory key number is defined by the result of adding camera position number and 9000. This function must be called after camera config or settings finished.
cam.startCapture(true, false); // support h264 encode frame and send it by udp

◆ startStereoCompute()

bool StereoCamera::startStereoCompute ( void  )
virtual

start stereo camera computing disparity thread

Parameters
[in]None
[out]None
Returns
true or false, if create thread successfully return true, otherwise return false
Attention
This function must be called after startCapture();
Note

◆ stopCapture()

bool StereoCamera::stopCapture ( void  )
virtual

stop stereo camera capture thread

Parameters
[in]None
[out]None
Returns
true or false, if stop thread successfully return true, otherwise return false
Attention
This function must be called after startCapture().
Note

◆ stopStereoCompute()

bool StereoCamera::stopStereoCompute ( void  )
virtual

stop stereo camera computing disparity thread

Parameters
[in]None
[out]None
Returns
true or false, if stop thread successfully return true, otherwise return false
Attention
This function must be called after startStereoCompute()
Note

The documentation for this class was generated from the following files: