Given sample code like in this previous question (error checking deleted for brevity):
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 );
And the classic OpenCV reading video loop:
cv::VideoCapture cap;
cap.open("/Testing/test.avi");
for(;;)
{
cv::Mat frame;
cap >> frame;
if( frame.empty() ) break;
// TODO: what goes here?
vxProcessGraph( graph );
}
How do I get the frame
into the inputImage
so I can call vxProcessGraph()
correctly? I know that:
vx_image image = nvx_cv::createVXImageFromCVMat(frame);
Is a helper for getting a vx_image
, but I cannot seem to find an example of what to do next. Some NVidia documentation I read suggested:
vxAccessImagePatch(...);
// copy pixel-by-pixel??
vxCommitImagePatch(...);
However, this seems a bit too brute-force-like, so is there some nicer way (vxSetParameter
, perhaps, but the documentation is very unclear) to do this?
I managed to work out the solution, as what was confusing me about examples was the use of a helper function not in the official API.
Now, my sample code above needs a quick modification:
Then the magic line of:
The
0
here means the 0th parameter to thesobel
node, excluding thegraph
itself.Next, my loop becomes:
Here, the 0 means the 0th parameter that we have added to the graph. If I had access the
vx_parameter p
above, there is the slightly less unfriendly:This might work on its own, but I don't know if there's extra work to do to notify the
vx_graph
of the change.