unsigned char* createImageBuffer(unsigned int bytes)
{
unsigned char* ptr;
cudaSetDeviceFlags(cudaDeviceMapHost);
cudaHostAlloc(&ptr, bytes, cudaHostAllocMapped);
return ptr;
}
cv::Mat sGray(frame.size(), CV_8U, createImageBuffer(frame.size().width * frame.size().height));
cv::Mat dGray(frame.size(), CV_8U, createImageBuffer(frame.size().width * frame.size().height));
cv::Mat eGray(frame.size(), CV_8U, createImageBuffer(frame.size().width * frame.size().height));
调试期间的问题是访问0x00000000处的受限内存 . 该函数应该返回一个指向图像字节分配位置的指针,但是它给了我糟糕的ptr值 .
输出:
improc.exe中0x0c10e473处的第一次机会异常:0xC0000005:访问冲突读取位置0x00000000 . improc.exe中0x0c10e473处的未处理异常:0xC0000005:访问冲突读取位置0x00000000 .
我遵循的教程视频:https://youtu.be/j9vb5UjQCQg
1 回答
API可能无法分配足够的内存 . 检查cudaHostAlloc的返回值(参见doku on cudaHostAlloc):