Skip to main content

Posts

Showing posts from 2015

Capture the webcam video in Java with OpenCV

I am going to capture the video from webcam of the computer/laptop in our Java program. I am using OpenCV for this. For this first obtain a fresh release of OpenCV and extract it under some location like C:\opencv\. I am using version 3.0.0. Now, we will define OpenCV as a user library in Eclipse, so we can reuse the configuration for any project. Launch Eclipse and select Window –> Preferences from the menu. Navigate under Java –> Build Path –> User Libraries and click New.... Enter a name, e.g. OPENCV-3.0.0 for new library. Now select your new user library and click Add External JARs.... Browse through C:\opencv\build\java and select opencv-300.jar. After adding the jar, extend the opencv-300.jar and select Native library location and press Edit.... Select External Folder... and browse to select the folder C:\opencv\build\java\x64. If you have a 32-bit system you need to select thex86 folder instead of x64...

Single LindedList in C. Program to create, insert, delete, traverse in Single Linked List.

For creating the LinkedList program I have used Linux(ubuntu 12.04) machine. When I was in my college days, I would use the Tourbo C compiler which was easy to use in Windows Type the following command to install the build-essential which create our environment and C  compiler to build and run C programs. This will be enough for our purpose to create C programs. $ sudo apt−get install build−essential SinglyLinkedList.c ----------------------- #include <stdio.h> #include <stdlib.h> /* Linded List is having an element and a pointer which points to the same type of structure. I have type defined a NODE type and given alias as "node". */ typedef struct NODE { int info; struct NODE *next; }node; /* I have created a boolean type which returns 0, 1 and 2 which returns false, true and done respectively. This is basically for return type to be used in the program to return boolean values. */ typedef enum {false, true, done}boolean; /* Now crea...

Java program to print numbers and strings when divisible by numbers 3 and 5

In one of the online assessment test a program is asked as to print the numbers from 1 to n where if the number is divisible by 3 then print "Fizz" and if number is divisible in 5 then print "Zeera" and if number is divisible completely by 3 and 5 then print "FizzZeera". The below program shows the java program when the input number is 35. package com.rohan.test; public class Test { public static void main(String[] args) { printNumbers(35); } public static void printNumbers(int n) { for(int i = 1; i<=n; i++) { int flag1 = 0, flag2 = 0; if(i%3 == 0) { flag1=1; } if(i%5 == 0) { flag2 = 1; } if(flag1 == 1 &&  flag2 == 1) { System.out.println("FizzJeera"); } else if(flag1 == 1 &&  flag2 == 0) { System.out.println("Fizz"); } else if(flag1 == 0 &&  flag2 == 1) { System.out.println("Jeera"); } else { System.ou...

Write a program in java to create two threads, one display odd and other display even numbers

Write a thread program in java to create two thread called even thread and odd thread and print the even numbers first and then odd numbers. Make sure that at all the run the program should print same output all the time, The output should be as follows : Even number = 0 Even number = 2 Even number = 4 Even number = 6 Even number = 8 Even number = 10 Odd number = 1 Odd number = 3 Odd number = 5 Odd number = 7 Odd number = 9 package com.rohan.test; /**  * @author ROHAN  *  */ public class EvenOddThread { public static void main(String[] args) { EvenOddThread eo = new EvenOddThread(); Runnable r2 = new PrintEvenThread(eo); Thread t1 = new Thread(r2); Runnable r1 = new PrintOddThread(eo); Thread t2 = new Thread(r1); t1.start(); t2.start(); } public synchronized void printOdd() { for(int i = 0; i<=10; i++) {     if(i % 2 != 0) System.out.println("Odd number = " + i); } } ...