How to rotate image in my camera's video? [closed]
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')
{
break;
}
Mat matOriginalFrame;
bool bSuccess = cap.read(matOriginalFrame);
if (!bSuccess)
{
cout << "Cannot read the frame from video file" << endl;
break;
}
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;
break;
}
}
return 0;
}
The error is at the line bool bSuccess = cap.read(matOriginalFrame); it said The identifier "cap" is not defined How can i fix this problem? thank you
so, you copypasted stuff, and forgot how the camera was named ?
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".
you'll also have to remove the duplicated image capturing code.
@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.
@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!
@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