Я пытаюсь написать короткий сценарий C++, который может показывать мне поток RTSP с камеры в моей локальной сети. В настоящее время мой сценарий выглядит следующим образом:
Код: Выделить всё
#include
#include
int main()
{
std::string window_name = "RGB Camera";
setenv("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp", 1);
const std::string rtsp_url = "rtsp://192.168.2.100:5010/video.sdp";
cv::VideoCapture cap; // Declare capture stream
cap.open(rtsp_url, cv::CAP_FFMPEG);
if (!cap.isOpened()) // Prompt an error message if no video stream is found
{
perror("Video Stream Error");
exit(EXIT_FAILURE);
}
cv::namedWindow(window_name, cv::WindowFlags::WINDOW_KEEPRATIO); // Declaring the video to show the video
cv::Mat frame; // Declaring a matrix to load the frames
while (1)
{
const bool read_success = cap.read(frame);
if (!read_success)
{
printf("End of stream\n.");
break;
}
cv::imshow(window_name, frame);
char c = (char)cv::waitKey(25); // 25 milliseconds per frame
if (c == 27) // If 'Esc' key is pressed, break the loop
{
printf("Esc key pressed, terminating loop...\n");
break;
}
}
cap.release(); // Release memory buffer
cv::destroyAllWindows(); // Close all windows
return 0;
}
Код: Выделить всё
Video Stream Error: Operation now in progress
Кроме того, когда я удаляю cv::CAP_FFMPEG в функции cap.open(), я получаю ошибка:
Код: Выделить всё
Video Stream Error: No such file or directory
Подробнее здесь: https://stackoverflow.com/questions/697 ... n-progress
Мобильная версия