资源简介
Kinect获取彩色图像并实时显示彩色图像信息,通过按下‘y’键将获取的彩色图像保存为jpg图片,程序可以连续获得jpg图片

代码片段和文件信息
#include “opencv2/core.hpp“
#include “opencv2/imgproc.hpp“
#include “opencv2/highgui.hpp“
#include “opencv2/videoio.hpp“
#include
#include
#pragma comment ( lib “kinect20.lib“ )
using namespace cv;
using namespace std;
int main()
{
HRESULT hResult = S_OK; //用于检测操作是否成功
IKinectSensor *kinect; //创建一个感应器
GetDefaultKinectSensor(&kinect);
kinect->Open(); //打开感应器
IColorframeSource *colorsource;
IColorframeReader *colorreader;
iframeDescription *colorde;
kinect->get_ColorframeSource(&colorsource);
colorsource->OpenReader(&colorreader);
colorsource->get_frameDescription(&colorde);
string colorName = “colorimage“;
uint count = 0;
int width = 0; //长和宽
int hight = 0;
colorde->get_Height(&hight);
colorde->get_Width(&width);
Mat a(hight width CV_8UC4); //注意:这里必须为4通道的图,Kinect的数据只能以Bgra格式传出
namedWindow(“彩色图像“);
cout << “press y to save image“ << endl;
cout << “press Esc to cancle saving image “ << endl;
while (1)
{
IColorframe*frame;
hResult = colorreader->AcquireLatestframe(&frame);
if (SUCCEEDED(hResult))
{
frame->CopyConvertedframeDataToArray(hight*width * 4 reinterpret_cast(a.data) ColorImageFormat::ColorImageFormat_Bgra); //传出数据
/*if (waitKey(0) == VK_ESCAPE)
break;
imshow(“彩色图像“ a);
colorName = “colorimage“ + to_string(count) + “.jpg“;
if (waitKey(0) == ‘y‘)
{
imwrite(colorName a);
cout << “saved “ << count << “ color image“ << endl;
count++;
}*/
}
if (frame != NULL) //释放
{
frame->Release();
frame = NULL;
}
if (waitKey(30) == VK_ESCAPE)
break;
imshow(“彩色图像“ a);
colorName = “colorimage“ + to_string(count) + “.jpg“;
if (waitKey(50) == ‘y‘)
{
imwrite(colorName a);
cout << “saved “ << count << “ color image“ << endl;
// imshow(“拍摄图像“ colorName);
count++;
}
}
if (colorsource != NULL) //全部释放掉
{
colorsource->Release();
colorsource = NULL;
}
if (colorreader != NULL)
{
colorreader->Release();
colorreader = NULL;
}
if (colorde != NULL)
{
colorde->Release();
colorde = NULL;
}
if (kinect)
{
kinect->Close();
}
if (kinect != NULL)
{
kinect->Release();
kinect = NULL;
}
destroyAllWindows();
}
//
//
//#include
//#include
//#include
//#include
//#include
//
//using namespace std;
//using namespace cv;
//
//// Safe release for interfaces
//template
//inline void SafeRelease(Interface *& pInterfaceToRelease)
//{
// if (pInterfaceToRelease != NULL)
// {
// pInterfaceToRelease->Release();
// pInterfaceToRelease = NULL;
// }
//}
//
//Mat ConvertMat(const UINT16* pBuffer int nWidth int nHeight USHORT nMinDepth USHORT nMaxDepth)
//{
// cv::Mat img(nHeight nWidth CV_8UC3);
// uchar* p_mat = img.data;
// const UINT16* pBufferEnd = pBuffer + (nWidth * nHeight);
// while (pBuffer < pBufferEnd)
// {
// USHORT depth = *pBuffer;
//
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6297 2018-11-26 22:21 获取彩色图像.cpp
- 上一篇:DirectX简单的贪吃蛇.rar
- 下一篇:黑苹果Clover驱动配置文件合集
相关资源
- 基于OpenCV的数字识别468815
- 使用opencv去掉二值化图像中黑色面积
- opencv环境配置
- win10 64位下编译的opencv4.5.5库,opencv
- NVIDIAOpticalFlowSDK-79c6cee80a2df9a196f20afd6
- opencv_contrib-3.4.0.zip
- opencv2.4.9源码分析——SIFT
- 用两个摄像头实现,双目标定,双目
- opencv_traincascade训练分类器,手势识别
- opencv3.0交叉编译用parallel.cpp
- 基于opencv的图像识别识别图像中的色
- 基于openCV的识别特定颜色区域
- 基于OpenCV的分水岭算法实现
- QT+opencv+OCR 身份证号码,银行卡号识别
- opencv视频特定颜色区域识别
- 把RGB转换为HSV和HSI然后根据黄色和蓝
- opencv视觉测距
- 基于Qt和opencv的身份证号码识别系统
- opencv_ffmpeg249.dll
- Kinect手势代替鼠标控制PC
- SfM稀疏三维点云重建--完整工程文件
- 基于opencv的数人头程序源代码
- 利用OpenCV中的Stitcher类实现全景图像拼
- opencv实现的sift算法源码,包含了图像
- openCV 上的小波变换
- 基于OPENCV的车牌识别系统设计
- 617张国内车牌60-17bmp图片用于OpenCV正样
- hog特征提取,c版本代码
- 基于Qt5.8+OpenCV3.2的Basler多相机触发开
- 基于Opencv实现的图像纠偏
评论
共有 条评论