資源簡介
包含源代碼及編譯好的文件。可直接執行。
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include??????????????/*?getopt_long()?*/
#include???????????????/*?low-level?i/o?*/
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include???????????/*?for?videodev2.h?*/
#include?
#include?“camera.h“
int?c_camera_type?=?0;
Camera::Camera(char?*DEV_NAME?int?w?int?h?int?camera_type)
{
????memcpy(dev_nameDEV_NAMEstrlen(DEV_NAME));
????io?=?IO_METHOD_MMAP;//IO_METHOD_READ;//IO_METHOD_MMAP;
????cap_image_size=0;
????width=w;
????height=h;
if(1?==?camera_type)
{
c_camera_type?=?1;
}
}
Camera::~Camera(){
}
unsigned?int?Camera::getImageSize(){
????return?cap_image_size;
}
void?Camera::CloseDevice()?{
????stop_capturing();
????uninit_device();
????close_device();
}
void?Camera::errno_exit(const?char?*?s)?{
????fprintf(stderr?“%s?error?%d?%s\n“?s?errno?strerror(errno));
????exit(EXIT_FAILURE);
}
int?Camera::xioctl(int?fd?int?request?void?*?arg)?{
????int?r;
????do
????????r?=?ioctl(fd?request?arg);
????while?(-1?==?r?&&?EINTR?==?errno);
????return?r;
}
int?Camera::read_frame(unsigned?char?*image)?{
????struct?v4l2_buffer?buf;
????CLEAR?(buf);
????buf.type?=?V4L2_BUF_TYPE_VIDEO_CAPTURE;
????buf.memory?=?V4L2_MEMORY_MMAP;
????if?(-1?==?xioctl(fd?VIDIOC_DQBUF?&buf))?{
????????switch?(errno)?{
????????case?EAGAIN:
printf(“**************?%s?line?=?%d\n“?__FUNCTION__?__LINE__);
????????????return?0;
????????case?EIO:
printf(“**************?%s?line?=?%d\n“?__FUNCTION__?__LINE__);
????????????/*?Could?ignore?EIO?see?spec.?*/
????????????/*?fall?through?*/
????????default:
printf(“**************?%s?line?=?%d\n“?__FUNCTION__?__LINE__);
????????????errno_exit(“VIDIOC_DQBUF“);
????????}
????}
printf(“**************?%s?line?=?%d\n“?__FUNCTION__?__LINE__);
????assert(buf.index? printf(“**************?%s?line?=?%d\n“?__FUNCTION__?__LINE__);
????memcpy(imagebuffers[0].startcap_image_size);
????if?(-1?==?xioctl(fd?VIDIOC_QBUF?&buf))
????????errno_exit(“VIDIOC_QBUF“);
????return?1;
}
void?Camera::stop_capturing(void)?{
????enum?v4l2_buf_type?type;
????switch?(io)?{
????case?IO_METHOD_READ:
????????/*?Nothing?to?do.?*/
????????break;
????case?IO_METHOD_MMAP:
????case?IO_METHOD_USERPTR:
????????type?=?V4L2_BUF_TYPE_VIDEO_CAPTURE;
????????if?(-1?==?xioctl(fd?VIDIOC_STREAMOFF?&type))
????????????errno_exit(“VIDIOC_STREAMOFF“);
????????break;
????}
}
bool?Camera::start_capturing(void)?{
????unsigned?int?i;
????enum?v4l2_buf_type?type;
printf(“**************?%s?line?=?%d\n“?__FUNCTION__?__LINE__);
????for?(i?=?0;?i?????????struct?v4l2_buffer?buf;
????????CLEAR?(buf);
????????buf.type?=?V4L2_BUF_TYPE_VIDEO_CAPTURE;
????????buf.memory?=?V4L2_MEMOR
評論
共有 條評論