//////////////////////////////////////////////////////////////////////
// Video Capture using DirectShow
// Author: Shiqi Yu (shiqi.yu@gmail.com)
// Thanks to:
// HardyAI@OpenCV China
// flymanbox@OpenCV China (for his contribution to function CameraName, and frame width/height setting)
// Last modification: April 9, 2009
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// 使用说明:
// 1. 将CameraDS.h CameraDS.cpp以及目录DirectShow复制到你的项目中
// 2. 菜单 Project->Settings->Settings for:(All configurations)->C/C++->Category(Preprocessor)->Additional include directories
// 设置为 DirectShow/Include
// 3. 菜单 Project->Settings->Settings for:(All configurations)->Link->Category(Input)->Additional library directories
// 设置为 DirectShow/Lib
//////////////////////////////////////////////////////////////////////
#include "camerads.h"
#include <stdio.h>
int main()
{
int cam_count;
//仅仅获取摄像头数目
cam_count = CCameraDS::CameraCount();
printf("There are %d cameras.\n", cam_count);
//获取所有摄像头的名称
for(int i=0; i < cam_count; i++)
{
char camera_name[1024];
int retval = CCameraDS::CameraName(i, camera_name, sizeof(camera_name) );
if(retval >0)
printf("Camera #%d's Name is '%s'.\n", i, camera_name);
else
printf("Can not get Camera #%d's name.\n", i);
}
if(cam_count==0)
return -1;
CCameraDS camera;
//打开第一个摄像头
//if (!camera.OpenCamera(0, true)){} //弹出属性选择窗口
if(! camera.OpenCamera(0, false, 640, 480)) //不弹出属性选择窗口,用代码制定图像宽和高
{
fprintf(stderr, "Can not open camera.\n");
return -1;
}
int tt=0, ltt=0;
cv::namedWindow("camera");
int et = -13;
while(1)
{
camera.SetExposure(et);
//获取一帧
IplImage *pFrame = camera.QueryFrame();
//std::cout<<"size = "<<pFrame->imageSize<<std::endl;
cv::Mat frame(480, 640, CV_16UC1, pFrame->imageData);
cv::Mat grey(480, 640, CV_8UC1);
uchar* p1 = frame.data;
uchar* p2 = grey.data;
tt = *(p1 + 638 * 2 + 1);
//printf("%02x %02x : %02x-%02x-%02x-%02x %d\n", *(unsigned char*)(p1 + 636 * 2), *(unsigned char*)(p1 + 636 * 2 + 1), *(p1 + 637 * 2), *(p1 + 637 * 2 + 1), *(p1 + 638 * 2), *(p1 + 638 * 2 + 1), tt-ltt);
ltt = tt;
//std::cout << (p1 + 637 * 2) << (p1 + 637 * 2 + 1) << (p1 + 638 * 2) << (p1 + 638 * 2 + 1) << std::endl; // << " " << *(p1 + 640 * 480 * 2 - 49) << " " << *(p1 + 640 * 480 * 2 - 48) << " " << *(p1 + 640 * 480 * -47) << std::endl;
for (size_t i = 0; i < 640*480; i++)
{
*p2 = (uchar)(*((ushort*)p1) >> 2);//10bit raw 去掉低2bit
p2++;
p1+=2;
}
cv::flip(grey, grey,1);
//显示
cv::imshow("camera", grey);
et++;
if (cvWaitKey(20) == 27)
break;
}
camera.CloseCamera(); //可不调用此函数,CCameraDS析构时会自动关闭摄像头
cvDestroyWindow("camera");
return 0;
}
CameraDS类Directshow camera raw10
最新推荐文章于 2025-05-05 14:10:45 发布
本文介绍了一个使用DirectShow进行视频捕获的示例程序。该程序由Shiqi Yu编写,能够获取连接到计算机上的摄像头数量及摄像头名称,并演示了如何打开摄像头、设置曝光并读取帧数据。
📄 AI 智能文档扫描仪 -
基于OpenCV透视变换算法,提供文档自动扫描与矫正服务,支持边缘检测、歪斜拉直及去阴影增强,集成WebUI,纯算法零依赖版
您可能感兴趣的与本文相关的镜像
📄 AI 智能文档扫描仪 -
图片编辑
Python
PyTorch
基于OpenCV透视变换算法,提供文档自动扫描与矫正服务,支持边缘检测、歪斜拉直及去阴影增强,集成WebUI,纯算法零依赖版

3137

被折叠的 条评论
为什么被折叠?



