jetson nx 使用opencv和gstreamer 硬解码

https://blog.csdn.net/jiexijihe945/article/details/125928135

RTSP:
"rtspsrc location=rtsp://stream.strba.sk:1935/strba/VYHLAD_JAZERO.stream latency=4000 ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv !  video/x-raw, width=1280, height=720, format=BGRx ! videoconvert ! appsink"

本地MP4:
"filesrc location=clip.mp4 ! qtdemux ! h264parse ! omxh264dec ! nvvidconv ! appsink"

USB摄像头:

"v4l2src device=/dev/video0 ! video/x-raw, width=1280, height=720 ! videoconvert ! appsink"

可以提前用  gst-launch-1.0 测试上面的pipeline是否有问题,例如测试 rtsp

gst-launch-1.0 rtspsrc location=rtsp://stream.strba.sk:1935/strba/VYHLAD_JAZERO.stream latency=4000 ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv !  video/x-raw, width=1280, height=720, format=BGRx ! videoconvert ! appsink

 

c++ / opencv  / gstreamer

#include 
#include 
#include 


void startCamera() {
	cv::VideoCapture cap;
	cap.open("clip.mp4");
	while (true) {
		cv::Mat frame;
		//方法一:>>析取器
		cap >> frame;  //每个循环从cap中解析一帧,赋给frame, 
		if (frame.empty()) {
			break;
		}
		//cv::imshow("frame", frame);
		//cv::waitKey(1);
		std::cout<<"frame :"<>析取器
		cap >> frame;  //每个循环从cap中解析一帧,赋给frame, 
		if (frame.empty()) {
			break;
		}
		//cv::imshow("frame", frame);
		//cv::waitKey(1);
		std::cout<<"frame :"<>析取器
		capture >> frame;  //每个循环从cap中解析一帧,赋给frame, 
		if (frame.empty()) {
			break;
		}
		//cv::imshow("frame", frame);
		//cv::waitKey(1);
		std::cout<<"frame :"< 1){
	// 	gst_src = argv[1];
	// }
	// startGStream(gst_src);

	std::string file_src = "rtsp://stream.strba.sk:1935/strba/VYHLAD_JAZERO.stream";
	int width = 1280;
	int height = 720;
	int latency = 5000;
	if (argc > 4){
		file_src = argv[1];
		width = atoi(argv[2]);
		height = atoi(argv[3]);
		latency = atoi(argv[4]);
	}
	startGStream(file_src, width, height, latency);
	std::cout<<"finished."<
cmake_minimum_required(VERSION 2.6)

project(decoder_test)

add_definitions(-std=c++11)

option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Release)

find_package(CUDA REQUIRED)

# if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
# 	message("embed_platform on")
# 	include_directories(/usr/local/cuda/targets/aarch64-linux/include)
# 	link_directories(/usr/local/cuda/targets/aarch64-linux/lib)
# else()
# 	message("embed_platform off")
# 	include_directories(/usr/local/cuda/include)
# 	link_directories(/usr/local/cuda/lib64)
#     # tensorrt
# 	include_directories(/usr/local/TensorRT-7.0.0.11/include)
# 	link_directories(/usr/local/TensorRT-7.0.0.11/lib)
# endif()

find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})


add_executable(decoder_test  ${PROJECT_SOURCE_DIR}/main.cpp)
target_link_libraries(decoder_test ${OpenCV_LIBS})

add_definitions(-O3 -Wall -pthread)

你可能感兴趣的:(opencv,人工智能,计算机视觉)