1
我有一個int數組,是在路的盡頭的位圖。我想暫時將數組轉換爲位圖,以便在最終形式呈現給屏幕之前,我可以在邊緣上進行平滑處理。我的代碼以平滑這裏的位圖:如何將int數組轉換爲位圖對象?
//.h file code:
using namespace Emgu::CV;
using namespace Emgu::CV::Structure;
namespace Microsoft
{
namespace Samples
{
namespace Kinect
{
namespace BodyIndexBasics
{
/// <summary>
/// Class responsible for extracting out the contours of an image.
/// </summary>
class FindContours
{
/// <summary>
/// Method used to process the image and set the output result images.
/// </summary>
/// <param name="colorImage">Source color image.</param>
/// <param name="thresholdValue">Value used for thresholding.</param>
/// <param name="processedGray">Resulting gray image.</param>
/// <param name="processedColor">Resulting color image.</param>
public:
void IdentifyContours(Bitmap *colorImage, int thresholdValue, bool invert, Bitmap *&processedGray, Bitmap *&processedColor);
};
}
}
}
}
//.cpp file code:
using namespace Emgu::CV;
using namespace Emgu::CV::Structure;
namespace Microsoft
{
namespace Samples
{
namespace Kinect
{
namespace BodyIndexBasics
{
void FindContours::IdentifyContours(Bitmap *colorImage, int thresholdValue, bool invert, Bitmap *&processedGray, Bitmap *&processedColor)
{
BlurBitmapEffect *myBlurEffect = new BlurBitmapEffect();
Image<Gray*, unsigned char> *grayImage = new Image<Gray*, unsigned char>(colorImage);
Image<Bgr*, unsigned char> *color = new Image<Bgr*, unsigned char>(new Bitmap(colorImage->Width, colorImage->Height));
grayImage = grayImage->ThresholdBinary(new Gray(thresholdValue), new Gray(255));
if (invert)
{
grayImage->_Not();
}
MemStorage *storage = new MemStorage();
try
{
for (Contour<Point> contours = grayImage->FindContours(Emgu::CV::CvEnum::CHAIN_APPROX_METHOD::CV_CHAIN_APPROX_SIMPLE, Emgu::CV::CvEnum::RETR_TYPE::CV_RETR_TREE, storage); contours != nullptr; contours = contours->HNext)
{
Contour<Point> *currentContour = contours->ApproxPoly(contours->Perimeter * 0.015, storage);
if (currentContour->BoundingRectangle->Width > 20)
{
CvInvoke::cvDrawContours(color, contours, new MCvScalar(255), new MCvScalar(255), -1, 5, Emgu::CV::CvEnum::LINE_TYPE::EIGHT_CONNECTED, Point(0, 0));
}
}
}
finally
{
if (storage != nullptr)
{
storage.Dispose();
}
}
processedColor = color->ToBitmap();
processedGray = grayImage->ToBitmap();
}
}
}
}
}
我需要的是某種方式爲int數組轉換爲位圖,這樣我可以渲染之前撫平它。
//This is the int array that I want to convert temp
int* pOutputData = nullptr;
byte* pOutputDataByte = nullptr;
hr = spOutputBufferByteAccess->Buffer(&pOutputDataByte);
if (FAILED(hr))
{
return false;
}
pOutputData = (int*)pOutputDataByte;
DepthSpacePoint* pDepthPoints = m_depthPoints->Data;
byte* pBodyIndexFrameArray = bodyIndexframeArray->Data;
ZeroMemory(pOutputData, outputDataBuffer->Capacity);
int * pOutputData是我想要轉換,以便我可以平滑它。
可以做到這一點嗎?
你也可以從int數組創建一個位圖,並且可以在不轉換位圖的情況下平滑一個int數組*。這裏有一個類似的問題:http://stackoverflow.com/q/13745093/3651800。是否有創建位圖的特定部分導致您的困難? – 2014-12-04 03:23:28
@MattCoubrough我沒有看到他在那裏談論一個int數組? – Robert 2014-12-05 00:06:30
您必須通過對數組中的每個項目進行簡單操作將「ints」的數組映射到字節,然後從字節數組構建一個位圖。我看到你已經接受了一個也需要這個答案。但是,從你的問題來看,我不清楚你想如何將整數映射到位圖像素。您只能說明整數的數組是「在路的盡頭的位圖」。每個int代表什麼?每個「int」是來自位圖的4字節RGBA值還是每個灰度像素亮度的數字,需要按比例縮放到一個字節或其他東西? – 2014-12-05 00:24:03