OpenCV3.3 problem using nsight [solved]

hello,
I have followed this link "http://petermoran.org/csi-cameras-on-tx2/ " to install OpenCV3.3 on my Jetson TX2 and also on my computer Host.
Then I tryed to compile the following example on nsight:

/*
  Example code for displaying gstreamer video from the CSI port of the Nvidia Jetson in OpenCV.
  Created by Peter Moran on 7/29/17.
  https://gist.github.com/peter-moran/742998d893cd013edf6d0c86cc86ff7f
*/

#include <opencv2/opencv.hpp>

template <typename T>
std::string to_string(T value)
{
	std::ostringstream os ;
	os << value ;
	return os.str() ;
}

std::string get_tegra_pipeline(int width, int height, int fps) {
    return "nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)" + to_string(width) + ", height=(int)" +
           to_string(height) + ", format=(string)I420, framerate=(fraction)" + to_string(fps) +
           "/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink";
}

int main() {
    // Options

	int WIDTH = 1920;
	int HEIGHT = 1080;
	int FPS = 30;

    // Define the gstream pipeline
    std::string pipeline = get_tegra_pipeline(WIDTH, HEIGHT, FPS);
    std::cout << "Using pipeline: \n\t" << pipeline << "\n";

    // Create OpenCV capture object, ensure it works.
    cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);
    if (!cap.isOpened()) {
        std::cout << "Connection failed";
        return -1;
    }

    // View video
    cv::Mat frame;
    while (1) {
        cap >> frame;  // Get a new frame from camera

        // Display frame
        imshow("Display window", frame);
        cv::waitKey(1); //needed to show frame
    }
}

So, the build failed and show me these messages:

Description Resource Path Location Type
make: *** [alpha] Error 1 alpha C/C++ Problem
undefined reference to cv::VideoCapture::~VideoCapture()' alpha line 35, external location: /home/nvidia/alpha/alpha.cpp C/C++ Problem undefined reference to cv::VideoCapture::VideoCapture(cv::String const&, int)’ alpha line 35, external location: /home/nvidia/alpha/alpha.cpp C/C++ Problem
undefined reference to cv::VideoCapture::isOpened() const' alpha line 36, external location: /home/nvidia/alpha/alpha.cpp C/C++ Problem undefined reference to cv::VideoCapture::operator>>(cv::Mat&)’ alpha line 44, external location: /home/nvidia/alpha/alpha.cpp C/C++ Problem
undefined reference to cv::imshow(cv::String const&, cv::_InputArray const&)' alpha line 47, external location: /home/nvidia/alpha/alpha.cpp C/C++ Problem undefined reference to cv::waitKey(int)’ alpha line 48, external location: /home/nvidia/alpha/alpha.cpp C/C++ Problem
undefined reference to cv::VideoCapture::~VideoCapture()' alpha line 50, external location: /home/nvidia/alpha/alpha.cpp C/C++ Problem recipe for target 'alpha' failed makefile /alpha/Debug line 58 C/C++ Problem undefined reference to cv::String::allocate(unsigned long)’ alpha line 601, external location: /usr/include/opencv2/core/cvstd.hpp C/C++ Problem
undefined reference to cv::String::deallocate()' alpha line 647, external location: /usr/include/opencv2/core/cvstd.hpp C/C++ Problem undefined reference to cv::String::deallocate()’ alpha line 655, external location: /usr/include/opencv2/core/cvstd.hpp C/C++ Problem
undefined reference to cv::fastFree(void*)' alpha line 692, external location: /usr/include/opencv2/core/mat.inl.hpp C/C++ Problem undefined reference to cv::Mat::deallocate()’ alpha line 804, external location: /usr/include/opencv2/core/mat.inl.hpp C/C++ Problem
undefined reference to `cv::String::allocate(unsigned long)’ alpha line 83, external location: /usr/include/opencv2/core/cvstd.inl.hpp C/C++ Problem

can anyone help me to fix it?

Best,
Danilo

Looks you’re missing opencv3.3 libs infos for linking.

Try adding to your link flags:

-L<path_to_opencv-3.3/lib>  -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_video -lopencv_videoio

Note that, for execution, you may need to set before:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path_to_opencv-3.3/lib>

Hi Honey_Patouceul,
Thanks you for answered. My question is:
how to add the libraries on Nsight Eclipse Edition?
I would to run the main.cpp by my computer host, without terminal.

Best,
Danilo

Hi Honey_Patouceul,
I understood how to add libraries,
now the build don’t fail.
So, when I try to run the application with Ensight show me:

Last login: Tue Oct 24 12:33:20 2017 from 192.168.1.35
echo $PWD'>'
/bin/sh -c "cd \"/home/nvidia/alpha/Debug\";export LD_LIBRARY_PATH=\"/usr/local/cuda-8.0/lib64\":\${LD_LIBRARY_PATH};export NVPROF_TMPDIR=\"/tmp\";\"/home/nvidia/alpha/Debug/alpha\"";exit
nvidia@tegra-ubuntu:~$ echo $PWD'>'
/home/nvidia>
nvidia@tegra-ubuntu:~$ /bin/sh -c "cd \"/home/nvidia/alpha/Debug\";export LD_LIBRARY_PATH=\"/usr/local/cuda-8.0/lib64\":\${LD_LIBRARY_PATH};export NVPROF_TMPDIR=\"/tmp\";\"/home/nvidia/alpha/Debug/alpha\"";exit
Using pipeline:
        nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)I420, framerate=(fraction)30/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink

Available Sensor modes :
2592 x 1944 FR=30.000000 CF=0x1109208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10
2592 x 1458 FR=30.000000 CF=0x1109208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10
1280 x 720 FR=120.000000 CF=0x1109208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10

NvCameraSrc: Trying To Set Default Camera Resolution. Selected sensorModeIndex = 1 WxH = 2592x1458 FrameRate = 30.000000 ...


(alpha:7928): Gtk-WARNING **: cannot open display:
logout

where “alpha” is the name of project

Hi,

Please check this comment:
https://devtalk.nvidia.com/default/topic/1010145/jetson-tx1/how-to-use-opencv3-1-with-nvidia-nsight-/post/5157413/#5157413

Thanks.

Hi AastaLLL,
Thanks you for answered.
So, I solved also the display problem and below I will try to explain how to fix it:

1. Right click -> properties;
2. Go on Run/Debug Settings;
3. Select your project and then click on Edit…;
4. Click on Environment and then click on New…;
5. Insert Name of display and set Value: :0.0
6. Click apply and now you are able to run the project.

Hi,

Not sure if you are meeting this issue:

OpenCV by default open Windows on the device side.
If you want to open a Windows on the host, please connect the device with ‘ssh -X nvidia@[IP]’.

Thanks.