我正在使用.png加载一个OpenCV文件,我希望使用推力库提取它的蓝色强度值。
我的代码是这样的:
IplImage指针加载图像thrust::device_vector中现在,我在从设备向量中提取蓝色强度值时遇到了问题。
FetchBlueValues。代码:
#define ImageWidth 14
#define ImageHeight 10
thrust::device_vector<int> BinaryImage(ImageWidth*ImageHeight);
thrust::device_vector<int> ImageVector(ImageWidth*ImageHeight*3);
struct FetchBlueValues
{
__host__ __device__ void operator() ()
{
int index = 0 ;
for(int i=0; i<= ImageHeight*ImageWidth*3 ; i = i+3)
{
BinaryImage[index]= ImageVector[i];
index++;
}
}
};
void main()
{
src = cvLoadImage("../Input/test.png", CV_LOAD_IMAGE_COLOR);
unsigned char *raw_ptr,*out_ptr;
raw_ptr = (unsigned char*) src->imageData;
thrust::device_ptr<unsigned char> dev_ptr = thrust::device_malloc<unsigned char>(ImageHeight*src->widthStep);
thrust::copy(raw_ptr,raw_ptr+(src->widthStep*ImageHeight),dev_ptr);
int index=0;
for(int j=0;j<ImageHeight;j++)
{
for(int i=0;i<ImageWidth;i++)
{
ImageVector[index] = (int) dev_ptr[ (j*src->widthStep) + (i*src->nChannels) + 0 ];
ImageVector[index+1] = (int) dev_ptr[ (j*src->widthStep) + (i*src->nChannels) + 1 ];
ImageVector[index+2] = (int) dev_ptr[ (j*src->widthStep) + (i*src->nChannels) + 2 ];
index +=3 ;
}
}
}发布于 2013-07-18 00:11:01
由于图像以像素格式存储,并且每个像素包含不同的颜色,因此在访问每个像素的各个颜色分量时有一个自然的“步幅”。在这种情况下,一个像素的颜色分量似乎存储在每个像素三个连续的int量中,因此给定颜色分量的访问步长为3。
本文介绍了一个跨距离范围访问迭代器方法的示例这里。
https://stackoverflow.com/questions/16793659
复制相似问题