Tuesday, 10 September 2013

opencv displaying an image over a video frame (with chessboard) - rotation of the image

opencv displaying an image over a video frame (with chessboard) - rotation
of the image

I didn't know what title would correctly describe my problem, I hope this
one is not confusing.
I started my adventure with OpenCV a few days ago. Until today I managed
to find a chessboard in a live stream from my internet camera and display
a resized image on it. My next goal is to make the program rotate the
image while I'm rotating the chessboard. Unfortunately I have no idea how
to do that, I saw many codes, many examples but none of them helped. My
last goal is to do something like this:
http://www.youtube.com/watch?v=APxgPYZOd0I (I can't get anything from his
code, he uses Qt, I only met it once and I'm not interested in it - yet).
Here is my code:
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
vector<Point3f> Create3DChessboardCorners(Size boardSize, float squareSize);
int main(int argc, char* argv[])
{
Size boardSize(6,9);
float squareSize=1.f;
namedWindow("Viewer", 1);
Mat zdjecie=imread("D:\\Studia\\Programy\\cvTest\\Debug\\zdjecie.png");
resize(zdjecie, zdjecie, Size(200,150));
vector<Point2f> corners;
VideoCapture video(0);
cout<<"video height: "<<video.get(CV_CAP_PROP_FRAME_HEIGHT)<<endl;
cout<<"video width: "<<video.get(CV_CAP_PROP_FRAME_WIDTH)<<endl;
Mat frame;
bool found;
Point2f src[4];
Point2f dst[4];
Mat perspMat;
while(1)
{
video>>frame;
found=findChessboardCorners(frame, boardSize, corners,
CALIB_CB_FAST_CHECK);
if(found &&
((corners[0].x+zdjecie.cols)<video.get(CV_CAP_PROP_FRAME_WIDTH)))
{
Rect roi(corners[0], zdjecie.size());
zdjecie.copyTo(frame(roi));
}
imshow("Viewer", frame);
if(waitKey(20)!=-1)
break;
}
return 0;
}
I was trying to understand this code:
http://dsynflo.blogspot.com/2010/06/simplar-augmented-reality-for-opencv.html
but nothing helped. It didn't even work for me - the image from my
webcamera was inverted, frames were changing every few seconds and nothing
was being displayed.
So what I ask for is not a whole solution. If someone explained me the way
how to do it, I'd be glad. I want to understand it from basics and I just
don't know where to go now. I spent much time on trying to solve it, if I
didn't, I would not bother you with my problem.
I'm lookin forward for you answers !
Greetings, Daniel

No comments:

Post a Comment