How to rotate image in my camera's video? [closed]

asked 2019-10-24 21:35:19 -0500

patrick129 gravatar image

updated 2019-10-25 00:56:42 -0500

berak gravatar image

I want to capture video frm my camera and rotate it at the same times and i've writing the program. But it has 1 error My written program is as below:

#include "opencv2/opencv.hpp"
#include "iostream"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;

int main(int argc, char* argv)
    VideoCapture camera(0);

    if (!camera.isOpened())
        return -1;
    int iAngle = 180;
    const char* OriginalWindowName = "Original Video";
    namedWindow(OriginalWindowName,1 );
    const char* RotatingWindowName = "Rotated Video";
    namedWindow(RotatingWindowName, 1);
    createTrackbar("Angle", RotatingWindowName, &iAngle, 360);
  while (1)
        Mat3b frame;
        camera >> frame;
        imshow("video", frame);
        if (waitKey(30) == 's')
        Mat matOriginalFrame;
        bool bSuccess =;
        if (!bSuccess)
            cout << "Cannot read the frame from video file" << endl;

        imshow(OriginalWindowName, matOriginalFrame);
        Mat matRotation = getRotationMatrix2D(Point(matOriginalFrame.cols / 2, matOriginalFrame.rows / 2), (iAngle - 180), 1);
        Mat matRotatedFrame;
        warpAffine(matOriginalFrame, matRotatedFrame, matRotation, matOriginalFrame.size());
        imshow(RotatingWindowName, matRotatedFrame);
        if (waitKey(30) == 27)
            cout << "esc key is pressed by user" << endl;

  return 0;

The error is at the line bool bSuccess =; it said The identifier "cap" is not defined How can i fix this problem? thank you

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by eshirima
close date 2019-10-26 13:36:01.096076


so, you copypasted stuff, and forgot how the camera was named ?

berak gravatar imageberak ( 2019-10-25 00:54:04 -0500 )edit

I think you are new in Opencv,I hope you solved your problem it's very simple, if not, replace "cap" by "camera" or "camera" by "cap".

Kitnos gravatar imageKitnos ( 2019-10-25 03:10:36 -0500 )edit

you'll also have to remove the duplicated image capturing code.

berak gravatar imageberak ( 2019-10-25 03:14:05 -0500 )edit

@berak I did this with the help of a forum and ye i didn't understand the code and copied it and saw that error.

patrick129 gravatar imagepatrick129 ( 2019-10-25 03:15:19 -0500 )edit

@Kitnos Thank you I've solved this problem with much easier code. Yes i'm new to the opencv and very stupid to realize the i've named the camera before. Anyway I'm grateful!

patrick129 gravatar imagepatrick129 ( 2019-10-25 03:17:38 -0500 )edit

@berak I'll try with this program and do as you say. I appreciate it so much. Lots of thanks!! Actually I think dont need to create 2 windows for 2 videos and capturing it by 2 codes

patrick129 gravatar imagepatrick129 ( 2019-10-25 03:22:27 -0500 )edit