Posts

Showing posts from 2014

Installing Glut

Image
Download the glut from this link:-

OpenGl - Displays a BARN shape on the XY plane.

Image
Source Code: 1: #include <windows.h> 2: #include <gl/Gl.h> 3: #include <gl/glut.h> 4: #include <cmath> 5: 6: int WinWidth = 500, WinHeight = 500; 7: 8: typedef struct{float x;float y;}Point2D; 9: typedef struct{float x;float y;float z;}Point3D; 10: 11: 12: Point3D COP = {100,100,-200}; 13: 14: Point3D A,B,C,D,E,F,G,H,I,J; // Vertices of the BARN 15: 16: void InitBarn(){ 17: A.x = 200; A.y = 100; A.z = 200; 18: B.x = 200; B.y = 00; B.z = 200; 19: C.x = 400; C.y = 00; C.z = 200; 20: D.x = 400; D.y = 100; D.z = 200; 21: E.x = 300; E.y = 200; E.z = 200; 22: 23: F.x = 200; F.y = 100; F.z = 400; 24: G.x = 200; G.y = 00; G.z = 400; 25: H.x = 400; H.y = 00; H.z = 400; 26: I.x = 400; I.y = 100; I.z = 400; 27: J.x = 300; J.y = 200; J.z = 400; 28: } 29: 30: void constructBarn(Point2D A, Point2D B, Point2D C, Point2D D

Alpha Blending Matlab Code

Image
Ibg=imread('E:\IP\codes\flower.jpg'); Ifg=imread('E:\IP\codes\beetle.jpg'); if length(size(Ibg))==3         Ibg=rgb2gray(Ibg); end if length(size(Ifg))==3         Ifg=rgb2gray(Ifg); end alpha = 0.2; [row,col] = size(Ibg); I = zeros(row,col); I = uint8(I); for i = 1:row     for j = 1:col         I(i,j) = alpha * Ibg(i,j) + (1 - alpha) * Ifg(i,j);     end end subplot(1,3,1); imshow(Ibg); subplot(1,3,2); imshow(Ifg); subplot(1,3,3); imshow(I);

Auto Contrast Matlab Code

Image
I=imread('E:\IP\imgs\lena.jpg'); amin = 0; amax = 255; if length(size(I))==3         I=rgb2gray(I); end alow = min(min(I)); ahigh = max(max(I)); [r,c] = size(I); J = zeros(r,c); for m=1:r     for n=1:c         a = I(m,n);         a1 = amin +((a - alow) * ((amax - amin) / (ahigh - alow)));         J(m,n) = a1;     end end J = uint8(J); subplot(1,2,1); imshow(I); subplot(1,2,2); imshow(J);

Filters

Difference between Point Operation and Filters         Filters generally used   more than one pixel from the source image for computing each new pixel values. The capability of Point operation is limited. For example, In Point operation can't blur or sharpen an image.        

Definitions

Digital Image Processing: Manipulate a digitalized image using a computer. Digital Image Editing: Manipulation of digital images using an existing software application such as Adobe Photoshop or Corel Paint Pixel: The smallest addressable unit of an image. Histogram: Frequency distribution of image intensities.

AI Techniques

Image
AI technique is a method of exploit knowledge. programs which are using AI technique are have disadvantages and advantages          Disadvantage AI technique programs are slower to execute            Advantages They are much less fragile People can easily understand what the program knowledge is They can work for large problems where more direct methods break down AI Techniques Search Use of Knowledge Abstraction

Characteristics of AI technique

Image
The knowledge capture generalization. It can be understood by people who must provide it. It can easily modified to correct errors and reflect changes in the world. It can be used a great many situations.

AI PROBLEMS

                                              Mundane Tasks Perception          -vision          -speech Natural language problem           -Understanding           -Generation           -Translation Commonsense reasoning Robot Control                       Formal Tasks Games          -Chess          -Backgammon          -Checkers-Go Mathematics          -Geometry          -Logic          -Integral calculus          -Proving properties of programs                       Expert Tasks Engineering         -Design         -Fault finding         -Manufacturing planning Scientific analysis Medical diagnosis Financial analysis

Deffinitions

Image
AI: Artificial intelligence(AI) is the study of how to make computer do things which, at the                   moment, people do better. AI TECHNIQUE: AI technique is a method that exploits the knowledge STATE SPACE: It contains all the possible configurations of the relevant object. STATE SPACE SEARCH: Define a problem as states and search the solutions by starting with a initial state, using set of rules moving one state to another and attempting to end up in one of a set of final states INITIAL STATES : Specify one or more states within the state space that describe possible situations to start problem-solving process GOAL STATES : Specify one or more states that would be acceptable as solution to the problem

Php mysql connection class with oop

<?php class dbConnect { var $host; var $username; var $password; var $database; function __construct($host,$username,$password,$database) { $this->host=$host; $this->username=$username; $this->password=$password; $this->database=$database; $this->connection(); } function connection() { $conn=mysqli_connect($this->host,$this->username,$this->password,$this->database); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } else echo "connected"; mysqli_close($conn); } } $log=new dbConnect("localhost","root","","login"); ?>

Java-Loops

Image
Loops are very useful mechanism to execute a code several times in java programming. Java has 3 looping mechanisms. They are For loop While loop do....while loop                           For Loop       For loop is very good choice if you know how many times a task wants to execute.       Basic syntax:                   for(initialization;expression;update)                  {                       //statements                   }       Example:                     public class ForLoop                   {                   public static void main(String args [])                  {                        for(int x=1;x<10;x++)                        {                          System.out.println(x);                        }                   }                    }        You can get the answer like this....                                  While loop     Basic syntax:                while(expression)          

Rotate a square with respect to the origin

#include <windows.h> #include <gl/Gl.h> #include <gl/glut.h> #include <cmath> int screenheight = 600; int screenwidth = 800; int flag = 0; double angle = 30;             typedef struct{     float x;     float y; }Point2D; Point2D p1,p2,p3,p4; void DrawSquare(Point2D pt1, Point2D pt2,Point2D pt3, Point2D pt4){        glPointSize(2.0);        glBegin(GL_LINE_LOOP);        glVertex2i(pt1.x, pt1.y);    glVertex2i(pt3.x, pt3.y);   glVertex2i(pt2.x, pt2.y);   glVertex2i(pt4.x, pt4.y);        glEnd();        glPointSize(5.0);        glBegin(GL_POINTS);        glVertex2i(pt2.x, pt2.y);        glEnd();        glFlush(); } Point2D translate(Point2D p, float tx, float ty){    p.x =p.x;    p.y = p.y;    return p; } Point2D  rotate(Point2D p, float ang){     ang = ang * 3.14 / 180.0;                                 Point2D ptemp;     ptemp.x = p.x * cos(ang) - p.y * sin(ang);     ptemp.y = p.x * sin(ang) + p.y * co

Rotate a square with respect to its centre

Image
#include <windows.h> #include <gl/Gl.h> #include <gl/glut.h> #include <cmath> int screenheight = 600; int screenwidth = 800; bool flag = true; int X1,Y1,X2,Y2,click; float len; float m; double angle = 30;                //The angle for the rotation (in degrees) typedef struct{     float x;     float y; }Point2D; Point2D p1,p2,p3,p4; void DrawLineSegment(Point2D pt1, Point2D pt2){        glPointSize(1.0);        glBegin(GL_LINES);        glVertex2i(pt1.x, pt1.y);        glVertex2i(pt2.x, pt2.y);        glEnd();        glPointSize(6.0);        glBegin(GL_POINTS);   glVertex2i(pt1.x, pt1.y);        glVertex2i(pt2.x, pt2.y);        glEnd();        glFlush(); } Point2D translate(Point2D p, float tx, float ty){        p.x =p.x+tx; //.....wite the equations for translation        p.y = p.y+ty; //.....wite the equations for translation        return p; } Point2D  rotate(Point2D p,float a

Rotate a line

#include <windows.h> #include <gl/Gl.h> #include <gl/glut.h> #include <cmath> int screenheight = 600; int screenwidth = 800; bool flag = true; double angle = 30; //The angle for the rotation (in degrees) typedef struct{ float x; float y; }Point2D; Point2D p1,p2; void DrawLineSegment(Point2D pt1, Point2D pt2){ glPointSize(1.0); glBegin(GL_LINES); glVertex2i(pt1.x, pt1.y); glVertex2i(pt2.x, pt2.y); glEnd(); glPointSize(6.0); glBegin(GL_POINTS); glVertex2i(pt2.x, pt2.y); glEnd(); glFlush(); } Point2D translate(Point2D p, float tx, float ty){ p.x =p.x; //.....wite the equations for translation p.y = p.y; //.....wite the equations for translation return p; } Point2D rotate(Point2D p, float ang){ ang = ang * 3.14 / 180.0; //angle in radians Point2D ptemp; ptemp.x = p.x * cos(ang) - p.y * sin(ang

GL_TRIANGLE_FAN Example In OpenGl

#include <GL/glut.h>       void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,0.0); glBegin(GL_TRIANGLE_FAN); glVertex3f(0.1, 0.1,0.0); glVertex3f(0.6, 0.1,0.0); glVertex3f(0.8,0.3,0.0); glVertex3f(0.6,0.6,0.0); glVertex3f(0.1,0.6,0.0); glVertex3f(0.0,0.3,0.0); glEnd(); glFlush(); } void init() { glClearColor(0.0,0.5,0.2,0.8); } int main(int argc, char** argv) { glutCreateWindow("simple 3D"); glutDisplayFunc(display); init(); glutMainLoop(); }

GL_POLYGON Example In OpenGl

#include <GL/glut.h>       void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,0.0); glBegin(GL_POLYGON); glVertex3f(0.1, 0.1,0.0); glVertex3f(0.6, 0.1,0.0); glVertex3f(0.8,0.3,0.0); glVertex3f(0.6,0.6,0.0); glVertex3f(0.1,0.6,0.0); glVertex3f(0.0,0.3,0.0); glEnd(); glFlush(); } void init() { glClearColor(0.0,0.5,0.2,0.8); } int main(int argc, char** argv) { glutCreateWindow("simple 3D"); glutDisplayFunc(display); init(); glutMainLoop(); }

GL_QUAD_STRIP Example In OpenGl

#include <GL/glut.h>       void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,0.0); glBegin(GL_QUAD_STRIP); glVertex3f(0.2, 0.2,0.0); glVertex3f(0.8, 0.2,0.0); glVertex3f(0.2,0.4,0.0); glVertex3f(0.8,0.4,0.0); glVertex3f(0.2,0.8,0.0); glVertex3f(0.8,0.8,0.0); glEnd(); glFlush(); } void init() { glClearColor(0.0,0.5,0.2,0.8); } int main(int argc, char** argv) { glutCreateWindow("simple 3D"); glutDisplayFunc(display); init(); glutMainLoop(); }

GL_QUADS Example In OpenGl

#include <gl glut.h="">          void display() { glClear(GL_COLOR_BUFFER_BIT);  glColor3f(1.0,1.0,0.0); glBegin(GL_QUADS); glVertex3f(0.2, 0.2,0.0); glVertex3f(0.8, 0.2,0.0); glVertex3f(0.6,0.4,0.0); glVertex3f(0.4,0.4,0.0); glVertex3f(0.4,0.6,0.0); glVertex3f(0.6,0.6,0.0); glVertex3f(0.8,0.8,0.0); glVertex3f(0.2,0.8,0.0); glEnd(); glFlush();  } void init() { glClearColor(0.0,0.5,0.2,0.8); } int main(int argc, char** argv) { glutCreateWindow("simple 3D");  glutDisplayFunc(display); init(); glutMainLoop(); }

GL_TRIANGLES Example In OpenGl

Image
#include <GL/glut.h>       void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,0.0); glBegin(GL_TRIANGLES); glVertex3f(0.2, 0.2,0.0); glVertex3f(0.8, 0.2,0.0); glVertex3f(0.2, 0.5,0.0); //glVertex3f(0.8, 0.5,0.0); //glVertex3f(0.2, 0.8,0.0); //glVertex3f(0.8, 0.8,0.0); glEnd(); glFlush(); } void init() { glClearColor(0.0,0.5,0.2,0.8); } int main(int argc, char** argv) { glutCreateWindow("simple 3D"); glutDisplayFunc(display); init(); glutMainLoop(); }

GL_TRIANGLE_STRIP Example In OpenGl

#include <GL/glut.h>          void display() { glClear(GL_COLOR_BUFFER_BIT);  glColor3f(1.0,1.0,0.0); glBegin(GL_TRIANGLE_STRIP); glVertex3f(0.2, 0.2,0.0); glVertex3f(0.8, 0.2,0.0); glVertex3f(0.2, 0.5,0.0); glVertex3f(0.8, 0.5,0.0); glVertex3f(0.2, 0.8,0.0); glVertex3f(0.8, 0.8,0.0); glEnd(); glFlush();  } void init() { glClearColor(0.0,0.5,0.2,0.8); } int main(int argc, char** argv) { glutCreateWindow("simple 3D");  glutDisplayFunc(display); init(); glutMainLoop(); }

GL_LINE_LOOP Example In OpenGl

#include <GL/glut.h>       void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,1.0,0.0); glBegin(GL_LINE_LOOP); glVertex3f(0.2, 0.2,0.0); glVertex3f(0.8, 0.2,0.0); glVertex3f(0.2, 0.5,0.0); glVertex3f(0.8, 0.5,0.0); glVertex3f(0.2, 0.8,0.0); glVertex3f(0.8, 0.8,0.0); glEnd(); glFlush(); } void init() { glClearColor(0.0,0.5,0.2,0.8); } int main(int argc, char** argv) { glutCreateWindow("simple 3D"); glutDisplayFunc(display); init(); glutMainLoop(); }

GL_LINE_STRIP Example In OpenGl

#include <GL/glut.h>          void display() { glClear(GL_COLOR_BUFFER_BIT);  glColor3f(1.0,1.0,0.0); glBegin(GL_LINE_STRIP); glVertex3f(0.2, 0.2,0.0); glVertex3f(0.8, 0.2,0.0); glVertex3f(0.2, 0.5,0.0); glVertex3f(0.8, 0.5,0.0); glVertex3f(0.2, 0.8,0.0); glVertex3f(0.8, 0.8,0.0); glEnd(); glFlush();  } void init() { glClearColor(0.0,0.5,0.2,0.8); } int main(int argc, char** argv) { glutCreateWindow("simple 3D");  glutDisplayFunc(display); init(); glutMainLoop(); }

Simple line drawing in OpenGl

#include <GL/glut.h>          void display(void) { glClear(GL_COLOR_BUFFER_BIT);  glColor3f(1.0,1.0,0.0); glBegin(GL_LINES); glVertex2f(0.5, -0.5); glVertex2f(-0.5, 0.5); glEnd(); glFlush();  } void init(){ glClearColor(0.0,0.5,0.2,0.8); } int main(int argc, char** argv) { glutCreateWindow("simple line");  glutDisplayFunc(display); init(); glutMainLoop(); }

GL_POINTS In OpenGl

#include <GL/glut.h> void display(void) { glClear(GL_COLOR_BUFFER_BIT); glPointSize(3.0); glBegin(GL_POINTS); glColor3f(1.0,1.0,0.0); glVertex2f(-0.5, -0.5); glColor3f(1.0,0.0,0.0); glVertex2f(-0.5, 0.5); glColor3f(0.0,0.0,1.0); glVertex2f(0.5, 0.5); glColor3f(0.0,1.0,0.0); glVertex2f(0.5, -0.5); glEnd(); glFlush(); } void init(){} int main(int argc, char** argv) { glutCreateWindow("simple"); glutDisplayFunc(display); init(); glutMainLoop(); }

Line drawing with mouse click event in OpenGl

#include <GL/glut.h>  int ww = 600, wh = 400; int first = 0; int xi, yi, xf, yf; void drawLine(int x1, int y1, int x2, int y2) { glClear(GL_COLOR_BUFFER_BIT); glLineWidth(5.0); glBegin(GL_LINES); glVertex2i(x1, y1); glVertex2i(x2, y2); glEnd(); glFlush(); } void display() { glClearColor(1.0, 1.0, 0.0, 1.0); glColor3f(1.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glFlush(); } void mouse(int btn, int state, int x, int y) { if(btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN) { switch(first) { case 0: xi = x; yi = (wh-y); first = 1; break; case 1: xf = x; yf = (wh-y); drawLine(xi,yi,xf,yf); first = 0; break; } } } void myinit() { glViewport(0,0,ww,wh); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,(GLdouble)ww,0.0,(GLdouble)wh); glMatrixMode(GL_MODELVIEW); } int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode (GLUT_SI

Restore mongoDb data

Image

Dump MongoDB Data

Image

Delete collection in mongodb

Image

Update document in mongodb

Image
Basic syntax of update() method is as follows db.COLLECTION_NAME.update (SELECTIOIN_CRITERIA, UPDATED_DATA)

Insert And Find In MongoDb

Image
To insert data into MongoDB collection, you need to use MongoDB's insert() or save()method. Basic syntax of insert() command is as follows: db.COLLECTION_NAME.insert(document) To query data from MongoDB collection, you need to use MongoDB's find() method. Basic syntax of find() method is as follows db.COLLECTION_NAME.find() To display the results in a pretty way, you can use pretty() method. SYNTAX: db.mycol.find().pretty() Apart from find() method there is findOne() method, that reruns only one document.

Drop Collections

Image
Basic syntax of drop collection command is as follows db.COLLECTION_NAME.drop()

Create Collections

Image
Basic syntax of createCollection() command is as follows db.createCollection(name, options) option is optional

drop database

Image
dropDatabase() command is used to drop a database

Create database

Image
Command use database_name is used to create a database. You can use any name for database_name. If you want to show the database you must want to insert atleast one document into it.

show dbs

Image
Command show dbs used to show all the databases

MongoDB Statistics

Image
Command db.stats() gives the detais of the particular database

MongoDB Help

Image
You can get mongodb commands and descriptions using db.help()

Getting start with mongoDb

Image
1. *open a cmd *change the directotry as mongodb installation didirectory. eg:- C:\mongodb\bin>mongod 2. *open another cmd *change the directotry as mongodb installation didirectory. eg:- C:\mongodb\bin>mongo Then you can work with the 2nd cmd

MongoDb Introduction

Image
*MongoDb is a Nosql database.This is something different from the RDBMS. *Colloction-This is like a table of RDBMS.

Time converting program in Java

Image
import java.util.*; public class TimeConvert { public static void main(String args[]) { Scanner s=new Scanner(System.in); System.out.println("Enter the value of seconds: "); int sec=s.nextInt(); int hr=sec/3600; int min=(sec-hr*3600)/60; sec=sec-(hr*3600+min*60); System.out.println(hr+"hours"+" "+min+"minites"+" "+sec+"seconds"); } }

Base Exponent program in Java

Image
public class Rec { public static double power(double base, int exponent) { if(exponent>0) { return (base*power(base,exponent-1)); } else if(exponent<0 data-blogger-escaped-br=""> { exponent=-exponent; return 1/(base*power(base,exponent-1)); } else { return 1; } } public static void main(String args []) { System.out.println(power(2,-3)); } }

Gcd program in java

Image
public class gcd1 { public static int gcd(int x,int y) { if(y==0) { return x; } else { return gcd(y,x%y); } } public static void main (String args []) { System.out.println(gcd(10,5)); } }

Fibonacci program in Java

Image
public class fibnocci { static int fib(int n) { if((n==1)|| (n==2)) return 1; else return fib(n-1)+fib(n-2); } public static void main(String [] args) { System.out.println("fibnocci(7)= "+ fib(7)); } }

Base converting program in Java

Image
public class Base { public void decTobase(int n,int b) { if(n>0) { decTobase(n/b,b); System.out.print(n%b); } } public static void main(String args []) { Base a=new Base(); a.decTobase(15,2); System.out.println(); a.decTobase(65,4); System.out.println(); a.decTobase(511,8); System.out.println(); }

Factorial program in Java

Image
public class factorial { static int fact(int n) { if(n==0 || n==1) return 1; else return n*fact(n-1); } public static void main(String [] args) { System.out.println("Factorial(4)="+fact(4)); } }

2D Array In Java

Image
public class TwoDArray { public static void main(String args[]) { int [][] a={{1,2,3},{4,5,6},{7,8,9}}; for(int row=0;row<3 data-blogger-escaped-br="" data-blogger-escaped-row=""> { for(int col=0;col<3 data-blogger-escaped-br="" data-blogger-escaped-col=""> System.out.print(a[row][col]); System.out.println(); } } }

Array Sums in Java

Image
class RowSum { int A[][]={{1,0,0,1},{1,-2,0,1},{-1,2,2,1}}; int B[][]={{1,1,-1,1},{0,1,-1,1},{0,0,1,1}}; int C[][]=new int[3][4]; void printArray() { for(int i=0;i<3 data-blogger-escaped-br="" data-blogger-escaped-i=""> { for(int j=0;j<4 data-blogger-escaped-br="" data-blogger-escaped-j=""> System.out.print(C[i][j]+" "); System.out.println(); } } void Addition() { for(int i=0;i<3 data-blogger-escaped-br="" data-blogger-escaped-i=""> { for(int j=0;j<4 data-blogger-escaped-br="" data-blogger-escaped-j=""> C[i][j]=A[i][j]+B[i][j]; } } public static void main(String args[]) { RowSum m=new RowSum(); m.Addition(); System.out.println("\n Array elements after addition:"); m.printArray(); } }

Metrix Operation In Java

Image
class MetrixOperation { int A[][]={{1,0,0},{1,1,0},{0,1,1}}; int B[][]={{1,1,1},{0,1,0},{0,0,1}}; int C[][]=new int[3][3]; void printArrayA() { for(int i=0;i<3;i++) { for(int j=0;j<3;j++) System.out.print(A[i][j]+" "); System.out.println(); } } void printArrayB() { for(int i=0;i<3;i++) { for(int j=0;j<3;j++) System.out.print(B[i][j]+" "); System.out.println(); } } void printXORArray() { for(int i=0;i<3;i++) { for(int j=0;j<3;j++) System.out.print(C[i][j]+" "); System.out.println(); } } void XOROperation() { for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { if(A[i][j]==B[i][j]) C[i][j]=0; else C[i][j]=1; } } } public static void main(String args[]) { MetrixOperation m=new MetrixOperation(); m.XOROperation(); System.out.println("\t"+"Metrix A :"); m.printArrayA(); System.

metrix program in Java

Image
class metrix { int m[][]={{1,2,13,4,5},{2,3,24,5,6},{3,4,35,6,7},{4,5,46,7,8}}; void printArray() { for(int i=0;i<4;i++) { for(int j=0;j<5;j++) System.out.print(m[i][j]+" "); System.out.println(); } } public static void main(String a[]) { metrix ab=new metrix(); ab.printArray(); } }

Simple Array Program in Java

Image
import java.util.*; public class ArrayOrder { public static void main(String args[]) { Scanner s=new Scanner(System.in); int a []={25,95,65,74,18}; int temp=0; int sum=0; double avg=0; double S=0; for(int i=0;i for(int j=0;j { if(a[j]>a[j+1]) { temp=a[j+1]; a[j+1]=a[j]; a[j]=temp; } } for(int b=0;b { sum=sum+a[b]; avg=sum/a.length; System.out.println(a[b]); S=S+Math.pow((a[b]-avg),2); } System.out.println("Meadian is: "+a[a.length/2]); System.out.println("minimum is: "+a[0]); System.out.println("Summation is: "+sum); System.out.println("Average is: "+avg); System.out.println("sd is:"+Math.sqrt(S/a.length-1)); } }