我有一个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是我想要转换的内容,以便我可以平滑它。
是否可以这样做?
答案 0 :(得分:1)
取决于您如何定义&#34; Bitmap&#34;。 Bitmap是GDI +位图吗?这是你创建的课程吗?它是一个带字节映射的文件吗?
如果它是GDI + Bitmap那么:http://msdn.microsoft.com/en-us/library/windows/desktop/ms536312(v=vs.85).aspx构造函数将正常工作,如下所示(OR http://msdn.microsoft.com/en-us/library/windows/desktop/ms536288(v=vs.85).aspx):
#include <gdiplus.h>
Gdiplus::Bitmap* CreateBitmap(void* data, unsigned int width, unsigned int height)
{
BITMAPINFO Info;
memset(&Info, 0, sizeof(Info));
Info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
Info.bmiHeader.biWidth = width;
Info.bmiHeader.biHeight = height;
Info.bmiHeader.biPlanes = 1;
Info.bmiHeader.biBitCount = 32;
Info.bmiHeader.biCompression = BI_RGB;
Info.bmiHeader.biSizeImage = 0; //(((32 * width + 31) & ~31) / 8) * height;
return new Gdiplus::Bitmap(&Info, data);
}
否则请在此处查看原始手动位图创建的答案:Incorrect Bitmap Copy/Output