Monday, 5 December 2016

Installing Tensorflow

Installation

# Ubuntu/Linux 64-bit
$ sudo apt-get install python-pip python-dev
$ export
TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.0rc0-cp27-none-linux_x86_64.whl

$ sudo pip install
--upgrade $TF_BINARY_URL


To check if installation is successfull :

$ python
>>> import tensorflow as tf
No error after this statement
CNTRL + z


Finding and adding path of the tensorflow

$ python -c 'import os; import inspect; import tensorflow;
print(os.path.dirname(inspect.getfile(tensorflow)))'

result : /usr/local/lib/python2.7/dist-packages/tensorflow



Friday, 14 October 2016

OpenCV Image in OpenGL

Objective :

To render OpenCV image captured from webcam into openGL window (GLUT)

Code :

#include <Windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/freeglut.h>

#include "opencv2\core\core.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\video\video.hpp"

using namespace cv;
using namespace std;

////////////////////////////////////////////DECLARATION///////////////////////////////////////////////////////
VideoCapture cap(0);
Mat frame;

void drawImage()
{
GLuint textureID;
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glEnable(GL_TEXTURE_2D);

//render image
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE, frame.data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBegin(GL_POLYGON);
glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex2f(-1.0f, 1.0f);
glEnd();
glFlush();
}

void display()
{
cap >> frame; //capture frame
flip(frame, frame, 0); //mirror around x axis
cvtColor(frame, frame, CV_BGR2RGB);
drawImage();

glFlush();
glutSwapBuffers();
}

int main(int argc, char **argv)
{
glutInit(&argc, argv); //GLUT initialization
glutInitWindowSize(640, 480); //define window size
glutInitWindowPosition(0, 0); //starting posiiton
glutCreateWindow("frame"); //name of the window
glutDisplayFunc(display); //set display function
glutIdleFunc(display); //idle function
glutMainLoop();
}