Hello, I'm looking for the way to show in a openGL window the video signal that I'm capturing from my ip camera with openCV. The reason that I need this is, because when the openGL window is activated I can send HTTP commands to my camera to move it with keyboard cursos.
I show you my code below, both OpenCV and OpenGL work perfectly independent, but I would like to integrate both. So you can see the video signal while you are moving it. Can you let me know how I can do this. I'm very new with OpenGL and OpenCV.
Thanks in advance.
#include "curlpp/cURLpp.hpp"
include "curlpp/Options.hpp"
include <opencv2 highgui="" highgui.hpp="">
include <stdio.h>
include <sstream>
include <iostream>
include <glut glut.h="">
using namespace std;
//Inicio curl curlpp::Cleanup myCleanup;
std::ostringstream os;
//process menu option 'op' void menu(int op) {
switch(op) {
case 'Q':
case 'q':
exit(0);
}
}
//executed when a regular key is pressed void keyboardDown(unsigned char key, int x, int y) {
switch(key) {
case 'Q':
case 'q':
case 27: // ESC
exit(0);
}
}
//executed when a regular key is released void keyboardUp(unsigned char key, int x, int y) {
}
//executed when a special key is pressed void keyboardSpecialDown(int k, int x, int y) {
switch(k)
{
case GLUT_KEY_UP:
{
//Mueve la camara hacia la arriba
os << curlpp::options::Url("http://192.168.1.90/axis-cgi/com/ptz.cgi?move=up");
}
break;
case GLUT_KEY_DOWN:
{
//Mueve la camara hacia la abajo
os << curlpp::options::Url("http://192.168.1.90/axis-cgi/com/ptz.cgi?move=down");
}
break;
case GLUT_KEY_LEFT:
{
//Mueve la camara hacia la izquierda
os << curlpp::options::Url("http://192.168.1.90/axis-cgi/com/ptz.cgi?move=left");
}
break;
case GLUT_KEY_RIGHT:
{
//Mueve la camara hacia la derecha
os << curlpp::options::Url("http://192.168.1.90/axis-cgi/com/ptz.cgi?move=right");
}
break;
}
}
//executed when a special key is released void keyboardSpecialUp(int k, int x, int y) {
}
//reshaped window void reshape(int width, int height) {
GLfloat fieldOfView = 90.0f;
glViewport (0, 0, (GLsizei) width, (GLsizei) height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluPerspective(fieldOfView, (GLfloat) width/(GLfloat) height, 0.1, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//render the scene void draw() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//render the scene here
glFlush();
glutSwapBuffers();
}
//executed when program is idle void idle() {
}
//initialize OpenGL settings void initGL(int width, int height) {
reshape(width, height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
//initialize GLUT settings, register callbacks, enter main loop int main(int argc, char** argv) {
//RECIBIR SEÑAL DE LA CAMARA
cv::VideoCapture camera;
camera.open("http://192.168.1.90/axis-cgi/mjpg/video.cgi?.mjpg");
if (camera.isOpened()==true)
{
cv::namedWindow("camera");
int key = 0;
while (key != 27)
{
cv::Mat_<cv::Vec3b> image;
camera.grab();
camera.retrieve(image);
cv::imshow("camera",image);
key = cv::waitKey(10);
}
}
else{
printf("No se puede leer la senal");
}
//cv::setOpenGlContext("camera");
//CONTROL DE LA CAMARA
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("Perspective's GLUT Template");
// register glut call backs
glutKeyboardFunc(keyboardDown);
glutKeyboardUpFunc(keyboardUp);
glutSpecialFunc(keyboardSpecialDown);
glutSpecialUpFunc(keyboardSpecialUp);
glutReshapeFunc(reshape);
glutDisplayFunc(draw);
glutIdleFunc(idle);
glutIgnoreKeyRepeat(true); // ignore keys held down
// create a sub menu
int subMenu = glutCreateMenu(menu);
glutAddMenuEntry("Do nothing", 0);
glutAddMenuEntry("Really Quit", 'q');
// create main "right click" menu
//glutCreateMenu(menu);
//glutAddSubMenu("Sub Menu", subMenu);
//glutAddMenuEntry("Quit", 'q');
//glutAttachMenu(GLUT_RIGHT_BUTTON);
//initGL(800, 600);
glutMainLoop();
return 0;
}