VisionWorks Refresh input OpenCV

Hello everyone,
looking at the VisionWorks examples I couldn’t find anything that showed how to use an input taken from an IP camera and used in the VisionWorks graph.

Following the stereo_match example, I wrote my code but I had the problem that the image of the disparity I got was always calculated on the first frame, so the problem was the refresh of the vx_image image that I was using in the graph because I use OpenCV for the IP camera so it was not enough for me to read the new frame and assign it to the vx_image variables

I solved the problem this way and I wanted to ask you if it was the right way to do it and at the same time I shared the piece of code so anyone who has the same problem can try it.

..
//stuff
..
right =vxCreateImageFromHandle(context,VX_DF_IMAGE_RGB,&right_addr,right_ptrs,VX_MEMORY_TYPE_HOST);
left = vxCreateImageFromHandle(context, VX_DF_IMAGE_RGB, &left_addr, left_ptrs, VX_MEMORY_TYPE_HOST);
..
//stuff
..
    std::unique_ptr<StereoMatching> stereo(
        StereoMatching::createStereoMatching(
            context, params,
            StereoMatching::HIGH_LEVEL_API,
            left, right, disparity));

 while(true){
        cap_left.read(frame_left);
	    cap_right.read(frame_right);
        cv::cvtColor(frame_left, frame_left, cv::COLOR_BGR2RGB);
        cv::cvtColor(frame_right, frame_right, cv::COLOR_BGR2RGB);

        void *left_ptrs_new[] = { frame_left.data };
        void *right_ptrs_new[] = { frame_right.data  };
        vxSwapImageHandle(left,left_ptrs_new,NULL,1);
        vxSwapImageHandle(right,right_ptrs_new,NULL,1);
        stereo->run();
..
//stuff
...
}

I used vxSwapImageHandle to change the reference of the vx_image with the new frame taken from openCV, is it right or wrong how do I do it?

The output image now changes so it works, but looking at the documentation I could also use vxMapImagePatch ,vxUnmapImagePatch, vxCopyImagePatch, even using these other functions I have the same result, between these two methods which one do you recommend? or is it possible to acquire the frame directly from the IP camera in a vx_image?

Thanks in advance

hi saromano:
1: vxSwapImageHandle : is correctly using here, which Once this function call has completed, the application gets back the ownership of the memory referenced by the previous handle. This memory contains up-to-date pixel data, and the application can safely reuse or release it.
2: vxMapImagePatch: it is get direct access to a rectangular patch of an image object plane.
3: vxUnmapImagePatch:it is unmapping an image patch invalidates the memory location from which the patch could be accessed by the application
4: vxCopyImagePatch: it it allows the application to copy a rectangular patch from/into an image object plane

for 2/3/4 is better for ROI set in your application, finally DONOT forget to release resource what you created

5:for camera directly acquire ,please reference :/usr/share/visionworks/sources/samples/nvgstcamera_capture which demonstrates NVIDIA GStreamer camera access

Thank you for your answer and for clarifying the points :D, for access to the IP camera I think it is not possible to interface directly with VisionWorks, but I have to use OpenCV.