给定示例代码,如 in this previous question (为简洁起见删除了错误检查):
vx_image inputImage = vxCreateImage( graph, width, height, VX_DF_IMAGE_S16 );
vx_image outputImage = vxCreateImage( graph, width, height, VX_DF_IMAGE_S16 );
vx_graph graph = vxCreateGraph( context );
vx_image intermediate1 = vxCreateVirtualImage( graph, width, height, VX_DF_IMAGE_S16 );
vx_image intermediate2 = vxCreateVirtualImage( graph, width, height, VX_DF_IMAGE_S16 );
vx_image intermediate3 = vxCreateVirtualImage( graph, width, height, VX_DF_IMAGE_S16 );
vxSobel3x3Node(graph,inputImage,intermediate1,intermediate2);
vxMagnitudeNode(graph,intermediate1,intermediate2,intermediate3);
vxConvertDepthNode(graph,intermediate3,outputImage,VX_CONVERT_POLICY_WRAP,0);
vxVerifyGraph( graph );
vxProcessGraph( graph );
以及经典的 OpenCV 阅读视频循环:
cv::VideoCapture cap;
cap.open("/Testing/test.avi");
for(;;)
{
cv::Mat frame;
cap >> frame;
if( frame.empty() ) break;
// TODO: what goes here?
vxProcessGraph( graph );
}
如何将 frame
放入 inputImage
中以便正确调用 vxProcessGraph()
?我知道:
vx_image image = nvx_cv::createVXImageFromCVMat(frame);
是获取 vx_image
的助手,但我似乎找不到下一步该做什么的示例。我阅读的一些 NVidia 文档建议:
vxAccessImagePatch(...);
// copy pixel-by-pixel??
vxCommitImagePatch(...);
但是,这似乎有点过于暴力,那么有没有更好的方法(vxSetParameter
,也许,但文档非常不清楚)来做到这一点?
最佳答案
可以创建一个仅引用存储在 cv::Mat
中的数据的 vx_image
。使用 vx_image
访问数据的东西最终会实际访问存储在 Mat
中的数据。此方法仅使用记录在案的 OpenCV 和 OpenVX功能。从这个Intel documentation :
vx_image get_vx_image_from_Mat(vx_context graph, cv::Mat &mat) {
vx_imagepatch_addressing_t frame_format {};
frame_format.dim_x = mat.cols;
frame_format.dim_y = mat.rows;
return vxCreateImageFromHandle(graph,
VX_DF_IMAGE_S16,
&format,
&((void*)mat.data),
VX_IMPORT_TYPE_HOST);
}
据推测,cv:Mat
需要至少与以这种方式创建的任何 vx_image
一样长。
关于c++ - 将新的 cv::Mat 送入 vx_graph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50012832/