資源簡(jiǎn)介
Kinect獲取彩色圖像并實(shí)時(shí)顯示彩色圖像信息,通過(guò)按下‘y’鍵將獲取的彩色圖像保存為jpg圖片,程序可以連續(xù)獲得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;?????//用于檢測(cè)操作是否成功
IKinectSensor?*kinect;???????????//創(chuàng)建一個(gè)感應(yīng)器
GetDefaultKinectSensor(&kinect);
kinect->Open();?????//打開(kāi)感應(yīng)器
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;??????//長(zhǎng)和寬
int?hight?=?0;
colorde->get_Height(&hight);
colorde->get_Width(&width);
Mat?a(hight?width?CV_8UC4);??????//注意:這里必須為4通道的圖,Kinect的數(shù)據(jù)只能以Bgra格式傳出
namedWindow(“彩色圖像“);
cout?<“press??y?to?save?image“?< cout?<“press?Esc?to?cancle?saving?image?“?< while?(1)
{
IColorframe*frame;
hResult?=?colorreader->AcquireLatestframe(&frame);
if?(SUCCEEDED(hResult))
{
frame->CopyConvertedframeDataToArray(hight*width?*?4?reinterpret_cast(a.data)?ColorImageFormat::ColorImageFormat_Bgra);???//傳出數(shù)據(jù)
/*if?(waitKey(0)?==?VK_ESCAPE)
break;
imshow(“彩色圖像“?a);
colorName?=?“colorimage“?+?to_string(count)?+?“.jpg“;
if?(waitKey(0)?==?‘y‘)
{
imwrite(colorName?a);
cout?<“saved?“?< 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?“?<// 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?// {
// USHORT?depth?=?*pBuffer;
//
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????6297??2018-11-26?22:21??獲取彩色圖像.cpp
評(píng)論
共有 條評(píng)論