【发布时间】:2014-12-04 03:00:10
【问题描述】:
我有一个 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数组而不转换为位图。这是一个类似的问题:stackoverflow.com/q/13745093/3651800。创建位图的特定部分是否给您带来了困难? -
@MattCoubrough 我没有看到他在那里谈论 int 数组?
-
您必须通过对数组中每个项目的简单操作将
ints数组映射到字节,然后从字节数组构建位图。我看到你已经接受了一个同样需要的答案。但是从你的问题中我并不清楚你想如何将你的整数映射到位图像素。您只声明整数数组是“路尽头的位图”。每个 int 代表什么?每个int是位图中的 4 字节 RGBA 值,还是需要缩放到一个字节或其他内容的每个灰度像素的亮度数字?