将 Basler 图像转换为 OpenCV
我正在尝试将从 Basler 相机捕获的帧转换为 OpenCV 的 Mat 格式。 Basler API 文档中没有提供太多信息,但是 Basler 示例中的这两行对于确定输出的格式应该很有用:
// Get the pointer to the image buffer
const uint8_t *pImageBuffer = (uint8_t *) Result.Buffer();
cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl << endl;
我知道图像格式是什么(当前设置为单声道) 8 位),并尝试过这样做:
img = cv::Mat(964, 1294, CV_8UC1, &pImageBuffer);
img = cv::Mat(964, 1294, CV_8UC1, Result.Buffer());
两者都不起作用。任何建议/建议将不胜感激,谢谢!
编辑:我可以通过以下方式访问 Basler 图像中的像素:
for (int i=0; i<1294*964; i++)
(uint8_t) pImageBuffer[i];
如果这有助于将其转换为 OpenCV 的 Mat 格式。
I'm trying to convert frames captured from a Basler camera to OpenCV's Mat format. There isn't a lot of information from the Basler API documentation, but these are the two lines in the Basler example that should be useful in determining what the format of the output is:
// Get the pointer to the image buffer
const uint8_t *pImageBuffer = (uint8_t *) Result.Buffer();
cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl << endl;
I know what the image format is (currently set to mono 8-bit), and have tried doing:
img = cv::Mat(964, 1294, CV_8UC1, &pImageBuffer);
img = cv::Mat(964, 1294, CV_8UC1, Result.Buffer());
Neither of which works. Any suggestions/advices would be much appreciated, thanks!
EDIT: I can access the pixels in the Basler image by:
for (int i=0; i<1294*964; i++)
(uint8_t) pImageBuffer[i];
If that helps with converting it to OpenCV's Mat format.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在创建 cv 图像以使用相机的内存,而不是拥有自己的内存的图像。问题可能是相机正在锁定该指针 - 或者可能希望在每个新图像上重新分配和移动它
尝试创建不带最后一个参数的图像,然后使用 memcpy() 将像素数据从相机复制到图像。
You are creating the cv images to use the camera's memory - rather than the images owning their own memory. The problem may be that the camera is locking that pointer - or perhaps expects to reallocate and move it on each new image
Try creating the images without the last parameter and then copy the pixel data from the camera to the image using memcpy().
从 Pylon cam 获取 Mat 框架的 C++ 代码
C++ code to get a Mat frame from a Pylon cam