Maison > développement back-end > C++ > le corps du texte

Comment faire pivoter une vidéo dans OpenCV en utilisant C++ ?

WBOY
Libérer: 2023-09-07 18:37:01
avant
476 Les gens l'ont consulté

La rotation des vidéos est similaire à la rotation des images. La seule différence est qu'au lieu de charger une image statique dans la matrice d'images, nous chargeons une vidéo ou obtenons un flux vidéo de la caméra.

Ici, au lieu de charger la vidéo, nous utilisons la caméra pour capturer la vidéo. Si vous souhaitez utiliser un fichier vidéo, entrez simplement l'adresse du fichier vidéo correctement.

Le programme suivant montre comment faire pivoter une vidéo dans OpenCV en utilisant C++.

Exemple 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;
}
Copier après la connexion

Sortie

Comment faire pivoter une vidéo dans OpenCV en utilisant C++ ?

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

source:tutorialspoint.com
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!