资源简介
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训练自己的分类器.doc
- opencv_calib3d310d.dll
- 利用OpenCV,通过SVM识别图像中图形链
- opencv2.4.11配置文件
- kinect 2.0获取深度和彩色帧并存为jpg图
- KinectFusion: Real-time 3D Reconstruction论文翻
- 图像特征之方向直方图OPENCV程序
- 遗传算法波段选择
- 图像二值化 opencv 基本全局阈值法
- OpenCV-根据颜色进行目标检测
- OpenCV轮廓提取的源代码
- opencv 中模板匹配的完整
- lee的caffe配置install-opencv-master.zip
- 专业图形工具Opencv For Unity的插件 v
- 车牌定位cascade文件
- opencv摄像机双目标定代码
- 基于Cascade的车牌检测文件 haar算法输
- Qt Creator+OpenCV410(vc14)开发的图片查
- 人脸识别Qt,opencv2.4.9
- 基于qt+opencv的人脸识别183028
- 最新Kinect v2 with MS-SDK 2.10.1 for Unity3D
- 已安装ROS-Kinectic的树莓派ubuntu16的im
- Kinect for unity sdk v2.9.unitypackage
- opencv 反透视变换矫正畸变
- 《Win10 opencv4.4 dnn cuda源码编译/安装说
- Dlib FaceLandmark Detector v1.2.0
- OPENCV技术.txt
- qt_opencv_zbar20181218二维码测距和识别检
- 基于OpenCV的手势识别--手掌和拳头识别
- sensor-win64-5.1.2.1-redist.msi
评论
共有 条评论