Can not use imshow() of opencv in vpi program

Hi, I’m trying to show the output image of vpi program. why can not make it successfully when i add imshow() of opencv to a vpi program, while imread() and imwrite() work well? Any help appriciated!——version vpi1.1, platform jetson tx2a , C++

Moved to TX2 forum for better support.

i put it on the tx2 forum originally, but

i really need some help urgently, please!

Hi,

Could you share your implementation so we can check it for you?
Thanks.

VPI - Vision Programming Interface: 2D Image Convolution (nvidia.com),
it just the sample program, i just add imshow() in the line 151 and #include<opencv2/highgui.hpp>.

just like this:
#include <opencv2/highgui.hpp>

imwrite(“edges_” + strBackend + “.png”, cvOut);
imshow(“img”, cvOut);

error is:

Hi,

cv::imshow works well in our environment.

If you link the device with ssh, please add the -X flag to allow window forwarding.
Ex,

 ssh -X nvidia@[IP]

Then we can show the output with the following changes to the 01-convolve_2d sample,

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5c588b9..fa233db 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,5 +37,5 @@ target_link_libraries(${PROJECT_NAME} vpi opencv_core opencv_imgproc)
 if(OpenCV_VERSION VERSION_LESS 3)
     target_link_libraries(${PROJECT_NAME} opencv_highgui)
 else()
-    target_link_libraries(${PROJECT_NAME} opencv_imgcodecs)
+    target_link_libraries(${PROJECT_NAME} opencv_imgcodecs opencv_highgui)
 endif()
diff --git a/main.cpp b/main.cpp
index 022e147..5d25ca2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -34,6 +34,7 @@
 #    include <opencv2/highgui/highgui.hpp>
 #endif
 
+#include <opencv2/highgui/highgui.hpp>
 #include <vpi/OpenCVInterop.hpp>
 
 #include <vpi/Image.h>
@@ -149,6 +150,8 @@ int main(int argc, char *argv[])
             cv::Mat cvOut(outData.planes[0].height, outData.planes[0].width, CV_8UC1, outData.planes[0].data,
                           outData.planes[0].pitchBytes);
             imwrite("edges_" + strBackend + ".png", cvOut);
+            cv::imshow("output", cvOut);
+            cv::waitKey(0);
 
             // Done handling output image, don't forget to unlock it.
             CHECK_STATUS(vpiImageUnlock(gradient));

Thanks.

problem was solved, thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.