> 백엔드 개발 > C++ > 본문

C++를 사용하여 OpenCV에서 비디오를 회전하는 방법은 무엇입니까?

WBOY
풀어 주다: 2023-09-07 18:37:01
앞으로
476명이 탐색했습니다.

비디오 회전은 이미지 회전과 유사합니다. 유일한 차이점은 정적 이미지를 이미지 매트릭스에 로드하는 대신 비디오를 로드하거나 카메라에서 비디오 스트림을 얻는다는 것입니다.

여기에서는 동영상을 로드하는 대신 카메라를 사용하여 동영상을 캡처합니다. 영상파일을 사용하시려면 영상파일의 주소를 정확하게 입력해주시면 됩니다.

다음 프로그램은 C++를 사용하여 OpenCV에서 비디오를 회전하는 방법을 보여줍니다.

예 H2>
#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main(int argc, char* argv[]) {
   VideoCapture loadvideo(0);//capture video from default camera//
   namedWindow("OriginalVideo");//declaring window to show original video stream//
   namedWindow("RotatedVideo");//declaring window to show rotated video stream//
   int rotating_angle = 180;//initial rotation angle//
   createTrackbar("Rotation", "RotatedVideo", &rotating_angle, 360);//creating trackbar for rotation//
   while (true) {
      Mat before_Rotating;//declaring matrix for image before rotation//
      bool temp = loadvideo.read(before_Rotating);//load frames from video source to matrix//
      imshow("OriginalVideo", before_Rotating);//show image frames before rotation//
      Mat for_Rotation = getRotationMatrix2D(Point(before_Rotating.cols / 2, before_Rotating.rows / 2), (rotating_angle - 180), 1);//affine transformation matrix for the 2D rotation//
      Mat after_Rotating;//declaring matrix for image after rotation//
      warpAffine(before_Rotating, after_Rotating, for_Rotation, before_Rotating.size());//applying affine transformation//
      imshow("RotatedVideo", after_Rotating);//show image after rotating//
      if (waitKey(30) == 27){ //wait till Esc key is pressed from keyboard//
         break;
      }
   }
   return 0;
}
로그인 후 복사

출력

C++를 사용하여 OpenCV에서 비디오를 회전하는 방법은 무엇입니까?

위 내용은 C++를 사용하여 OpenCV에서 비디오를 회전하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:tutorialspoint.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!