How to open CSI Camera on Xavier NX?

build Ros2 Foxy source code on BOTH PC and NX.
ros2 run image_tools cam2image
ros2 run image_tools showimage

when run PC above nodes, it work well, but cannot run NX, since failed open camera.
There is a camera in /dev/video0

some code for open camera
cv::VideoCapture cap;

// Initialize OpenCV video capture stream.
// Always open device 0.
cap.open(0);

  // Set the width and height based on command line arguments.
  cap.set(cv::CAP_PROP_FRAME_WIDTH, static_cast<double>(width_));
  cap.set(cv::CAP_PROP_FRAME_HEIGHT, static_cast<double>(height_));
  if (!cap.isOpened()) {
    RCLCPP_ERROR(this->get_logger(), "Could not open video stream");
    throw std::runtime_error("Could not open video stream");
  }
}

Thanks for your help!

Have a try below python code for OpenCv.