2
我正在處理從16位的kinect中檢索的深度圖像。由於圖像的索引或大小,我在製作自己的濾鏡時遇到了一些困難。 我正在使用紋理,因爲它允許使用任何位圖大小的圖像。在16位圖像上使用紋理的C++ AMP計算漸變
所以,我試圖計算一個簡單的漸變,以瞭解什麼是錯的或爲什麼它不工作,因爲我的預期。
您可以看到,當我使用y dir時出現了問題。
這是我的代碼:
typedef concurrency::graphics::texture<unsigned int, 2> TextureData;
typedef concurrency::graphics::texture_view<unsigned int, 2> Texture
cv::Mat image = cv::imread("Depth247.tiff", CV_LOAD_IMAGE_ANYDEPTH);
//just a copy from another image
cv::Mat image2(image.clone());
concurrency::extent<2> imageSize(640, 480);
int bits = 16;
const unsigned int nBytes = imageSize.size() * 2; // 614400
{
uchar* data = image.data;
// Result data
TextureData texDataD(imageSize, bits);
Texture texR(texDataD);
parallel_for_each(
imageSize,
[=](concurrency::index<2> idx) restrict(amp)
{
int x = idx[0];
int y = idx[1];
// 65535 is the maxium value that can take a pixel with 16 bits (2^16 - 1)
int valX = (x/(float)imageSize[0]) * 65535;
int valY = (y/(float)imageSize[1]) * 65535;
texR.set(idx, valX);
});
//concurrency::graphics::copy(texR, image2.data, imageSize.size() *(bits/8u));
concurrency::graphics::copy_async(texR, image2.data, imageSize.size() *(bits));
cv::imshow("result", image2);
cv::waitKey(50);
}
任何幫助將是非常讚賞。
我認爲你的圖像texR.set(idx,valX)和texR.set(idx,valY)可能會顛倒? –
你是什麼意思與顛倒? x的漸變使用texR.set(idx,valX);並將y更改爲texR.set(idx,valY); – dmayola