Showing posts with label Skill. Show all posts
Showing posts with label Skill. Show all posts
Friday, 17 June 2016
Ubuntu News Application
Synopsis:
The Ubuntu News Application is a python script which takes the input i.e the category of input that user wants the news to be and from that category
the script will try to fetch the latest news from the CNN news Website
and push the titles of the news as a notification in Ubuntu.
Execution:
Execution:
Command : python Ubuntu_News_App.py
Script Link :
Friday, 26 February 2016
Segmentation Using Canny+Watershed in Opencv-python
import cv2
# Importing opencv libraryimport numpy as np
# Importing NumPy,which is the fundamental package for scientific computing with Python
img = cv2.imread('C:\\Users\Ram\Pictures\\humans\\368078.jpg')
# Read the image from disk
cv2.imshow("Original image", img) # Display image
img_float = np.float32(img) # Convert image from unsigned 8 bit to 32 bit float
criteria = (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 10, 1)
# Defining the criteria ( type, max_iter, epsilon )
# cv2.TERM_CRITERIA_EPS - stop the algorithm iteration if specified accuracy, epsilon, is reached.
# cv2.TERM_CRITERIA_MAX_ITER - stop the algorithm after the specified number of iterations, max_iter.
# cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER - stop the iteration when any of the above condition is met.
# max_iter - An integer specifying maximum number of iterations.In this case it is 10
# epsilon - Required accuracy.In this case it is 1
k = 50 # Number of clusters
ret, label, centers = cv2.kmeans(img_float, k, None, criteria, 50, cv2.KMEANS_RANDOM_CENTERS)
# apply kmeans algorithm with random centers approach
center = np.uint8(centers)
# Convert the image from float to unsigned integer
res = center[label.flatten()]
# This will flatten the label
res2 = res.reshape(img.shape)
# Reshape the image
cv2.imshow("K Means", res2) # Display image
cv2.imwrite("1.jpg", res2) # Write image onto disk
meanshift = cv2.pyrMeanShiftFiltering(img, sp=8, sr=16, maxLevel=1, termcrit=(cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 5, 1))
# Apply meanshift algorithm on to image
cv2.imshow("Output of meanshift", meanshift)
# Display image
cv2.imwrite("2.jpg", meanshift)
# Write image onto disk
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Convert image from RGB to GRAY
ret, thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# apply thresholding to convert the image to binary
fg = cv2.erode(thresh, None, iterations=1)
# erode the image
bgt = cv2.dilate(thresh, None, iterations=1)
# Dilate the image
ret, bg = cv2.threshold(bgt, 1, 128, 1)
# Apply thresholding
marker = cv2.add(fg, bg)
# Add foreground and background
canny = cv2.Canny(marker, 110, 150)
# Apply canny edge detector
new, contours, hierarchy = cv2.findContours(canny, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# Finding the contors in the image using chain approximation
marker32 = np.int32(marker)
# converting the marker to float 32 bit
cv2.watershed(img,marker32)
# Apply watershed algorithm
m = cv2.convertScaleAbs(marker32)
ret, thresh = cv2.threshold(m, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# Apply thresholding on the image to convert to binary image
thresh_inv = cv2.bitwise_not(thresh)
# Invert the thresh
res = cv2.bitwise_and(img, img, mask=thresh)
# Bitwise and with the image mask thresh
res3 = cv2.bitwise_and(img, img, mask=thresh_inv)
# Bitwise and the image with mask as threshold invert
res4 = cv2.addWeighted(res, 1, res3, 1, 0)
# Take the weighted average
final = cv2.drawContours(res4, contours, -1, (0, 255, 0), 1)
# Draw the contours on the image with green color and pixel width is 1
cv2.imshow("Watershed", final) # Display the image
cv2.imwrite("3.jpg", final) # Write the image
cv2.waitKey() # Wait for key stroke
The result of the above script is given in the pdf below (2nd Answer):
Friday, 18 December 2015
How to Install open CV 3.0.0 in UBUNTU 15.04
Step 1:Download open CV
open the link to download open CV 3.0:
Step 2:Extraction
Extract the downloaded archive to any arbitrary folder.
Step 3:Installing the Dependencies:
open terminal and follow the below steps or you can download the script file and run it (with sudo privileges):
- sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip
Go to the extracted folder named opencv-3.0.0 and then start typing the following commands:
- mkdir build
- cd build
- cmake -D WITH_CUDA=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_OPENGL=ON ..
- sudo make -j4
- sudo make install
Step 4: Finishing installation
- sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
- sudo ldconfig
Step 6:Testing(Download this file and extract it and go to that directory and then type these commands)
- sudo cmake .
- sudo make
- ./DisplayImage lena.jpg
Thursday, 17 December 2015
C Code to Perform Sampling Rate Convertion
Sampling Rate Conversion in Real Time(Using a C language)
Upsampling and DownSampling using Reconstruction
(Using sinc Function):
Code:
#include<stdio.h>#include<math.h>
#define PI 3.14
void main()
{
int m,n,samplingrate,chunksize,subchunk2size,newchunksize,newsamplingrate,newsubchunk2size;
float i;
//int noofsamples;
int factor;
unsigned char a,b,c,d,e;
FILE *fp,*fp2;
void writeheaderfile(FILE *fp,int newsamplingrate,int newchunksize,int newsubchunk2size,FILE *fp2);
void writedatafile(FILE *fp,int newsamplingrate,int newchunksize,int newsubchunk2size,float i,int subchunk2size,FILE *fp2);
printf("Original Song is in : song1.wav\nResult is stored in : Createdsong.wav\n");
fp=fopen("song1.wav","r");
fp2=fopen("Createdsong.wav","w+");
fseek(fp,24,SEEK_SET);
fread(&samplingrate,4,1,fp);
printf("Sampling Rate is : %d\n",samplingrate);
fseek(fp,4,SEEK_SET);
fread(&chunksize,4,1,fp);
printf("chunksize is : %d\n",chunksize);
fseek(fp,40,SEEK_SET);
fread(&subchunk2size,4,1,fp);
printf("subchunk2size is : %d\n",subchunk2size);
printf("Enter the New Sampling Rate : ");scanf("%d",&newsamplingrate);
i=(float)samplingrate/newsamplingrate;
//printf("I value is : %f\n",i);
//noofsamples=readnoofsamples(fp);
printf("No of Samples in Given File : %d\n",subchunk2size/4);
newsubchunk2size=subchunk2size/i;
newchunksize=newsubchunk2size+36;
//noofsamples=newsubchunk2size/4;
writeheaderfile(fp,newsamplingrate,newchunksize,newsubchunk2size,fp2);
//fclose(fp2);
// fp2=fopen("Createdsong.wav","w+");
writedatafile(fp,newsamplingrate,newchunksize,newsubchunk2size,i,subchunk2size,fp2);
}
/*int readnoofsamples(FILE *fp)
{
int count=1;
unsigned char c;
fp=fopen("song1.wav","r");
fseek(fp,44,SEEK_SET);
while(1)
{
if(feof(fp)) break;
fscanf(fp,"%c",&c);
count++;
//printf("%d\n",count);
}
//count=count/4;
return count;
}*/
void writedatafile(FILE *fp,int newsamplingrate,int newchunksize,int newsubchunk2size,float i,int subchunk2size,FILE *fp2)
{
//FILE *fp2;
int count=0,samco=1,center,samp=0,previous=0,x,temp;
short int e,r;
long int m,n,sumfr,sumfl;
float suml=0,sumr=0;
unsigned char z,s,v,w,c;
float sinc(int m,float i,int n);
printf("Writing the Samples in File....Please Wait....\n");
//fp=fopen("song1.wav","r");
fseek(fp,40,SEEK_SET);
fread(&subchunk2size,4,1,fp);
//printf("subchunk2size is : %d\n",subchunk2size);
//fclose(fp);
//fp=fopen("song1.wav","r");
//fp2=fopen("Createdsong.wav","a");
fseek(fp,44,SEEK_SET);
fseek(fp2,44,SEEK_SET);
//printf("%d\n",subchunk2size);
for(m=0;m<=subchunk2size;m++)
{
//if(feof(fp)) break;
sumfl=0;
sumr=0;
suml=0;
sumfr=0;
center=rint(m*i);
if(previous==center)
{
}
else
{
for(temp=0;temp<(center-previous);temp++)
{
count++;
}
}
previous=center;
fseek(fp,44+(4*count),SEEK_SET);
for(n=count-10;n<count+10;n++)
{
//printf("m value : %d\n",m);
if(n<0)
{
e=0;
r=0;
}
else
{
fread(&e,2,1,fp);
fread(&r,2,1,fp);
}
sumr=sumr+(e*sinc(m,i,n));
suml=suml+(r*sinc(m,i,n));
sumfl=suml;
sumfr=sumr;
//if(sumfl==0) printf("m=%d\t n=%d\n",m,n);
//printf("m*I=%d\t n=%d\t e=%d\n",m*i,n,e);
//printf("suml=%lf\t sumr=%lf\t n=%d\t count=%d\t e=%d\t r=%d\n",suml,sumr,n,count,e,r);
}
fwrite(&sumfr,2,1,fp2);
fwrite(&sumfl,2,1,fp2);
/*fscanf(fp,"%c",&t);
fscanf(fp,"%c",&s);
fscanf(fp,"%c",&v);
fscanf(fp,"%c",&w);
printf("%d %d %d %d\n",t,s,v,w);*/
//if(sumfr==0) printf("m=%d\t and n=%d\n",m,n);
//printf("m=%d\t and sumfl=%d\t sumfr=%d\n",m,sumfl,sumfr);
//getchar();
}
printf("Process Completed...Result is in Createdsong.wav\n");
fclose(fp);
fclose(fp2);
}
float sinc(int m,float i,int n)
{
float temp;
if(rint(m*i)==n)
{
//printf("sinc value is : %f\n",1.00);
return 1.00;
}
else
{
temp=PI*(m*i-n);
//printf("sinc value is : %f\n",(sin(temp)/temp));
return (sin(temp)/temp);
}
}
void writeheaderfile(FILE *fp,int newsamplingrate,int newchunksize,int newsubchunk2size,FILE *fp2)
{long int count=1;
unsigned char header;
//FILE *fp2;
//fp=fopen("song1.wav","r");
//fp2=fopen("Createdsong.wav","w+");
fseek(fp,0,SEEK_SET);
while(1)
{
fread(&header,4,1,fp);
fwrite(&header,4,1,fp2);
if(ftell(fp)==44) break;
}
fseek(fp2,4,SEEK_SET);
fwrite(&newchunksize,4,1,fp2);
fseek(fp2,24,SEEK_SET);
fwrite(&newsamplingrate,4,1,fp2);
fseek(fp2,40,SEEK_SET);
fwrite(&newsubchunk2size,4,1,fp2);
//fclose(fp2);
//fclose(fp);
//printf("Suc\n");
}
Down Sampling using Decimation(Without Using Sinc Function):
Code:#include<stdio.h>
void main()
{
FILE *fp,*fp2;
unsigned char down;
int samplingrate,ratio,i=4,chunksize,subchunk2size,newchunksize,newsubchunk2size;
int newsamplingrate;
long int count=1;
//Getting the Sampling Rate from the File
// while(1)
// {
fp=fopen("mono.wav","r");
fseek(fp,24,SEEK_SET);
fread(&samplingrate,4,1,fp);
rewind;
fseek(fp,4,SEEK_SET);
fread(&chunksize,4,1,fp);
rewind;
fseek(fp,40,SEEK_SET);
fread(&subchunk2size,4,1,fp);
//fscanf(fp,"%d",&sample);
//**fprintf(stdout,"samplingrate is %u\n chunksize is : %u\nsubchunk2size is : %u\n",samplingrate,chunksize,subchunk2size);
//count++;
//if(count>44) break;
//}
//printf("The count value is : %ld\n",count-1);
fclose(fp);
//printf("Enter the New Sampling Rate : ");scanf("%d",&newsamplingrate);
newsamplingrate=5000;
if(newsamplingrate<samplingrate)
{
ratio=samplingrate/newsamplingrate;
fp=fopen("song1.wav","r");
fseek(fp,44,SEEK_SET);
while(1)
{
fscanf(fp,"%c",&down);
//fprintf(stdout,"%d\t",down);
count++;
i--;
if(feof(fp)) break;
if(i<1)
{
i=4;
fseek(fp,SEEK_CUR+4*(ratio-1)-1,SEEK_CUR);
}
}
fclose(fp);
count=count/4;
// printf("Count is : %ld\n",count);
newsubchunk2size=chunksize/3;
newchunksize=newsubchunk2size+36;
writeheaderfile(fp,newsamplingrate,newchunksize,newsubchunk2size);
writedatafile(fp,newsamplingrate,newchunksize,newsubchunk2size,ratio);
}
/*if(newsamplingrate>samplingrate)
{
ratio=newsamplingrate/samplingrate;
fp=fopen("song1.wav","r");
fseek(fp,44,SEEK_SET);
newsubchunk2size=chunksize*3;
newchunksize=newsubchunk2size+36;
writeheaderfile(fp,newsamplingrate,newchunksize,newsubchunk2size);
writedataupfile(fp,newsamplingrate,newchunksize,newsubchunk2size,ratio);
}*/
}
//Writing the Header Section
void writeheaderfile(FILE *fp,int newsamplingrate,int newchunksize,int newsubchunk2size)
{long int count=1;
unsigned char header;
FILE *fp2;
fp=fopen("mono.wav","r");
fp2=fopen("song2.wav","w+");
//rewind;
while(1)
{
fread(&header,4,1,fp);
//if(ftell(fp)==5) fprintf(fp2,"%c",newchunksize);
//else if(ftell(fp)==17) fprintf(fp2,"%c",newsubchunk2size);
//else if(ftell(fp)==25) fprintf(fp2,"%c",newsamplingrate);
//else fprintf(fp2,"%c",header);
fwrite(&header,4,1,fp2);
if(ftell(fp)==44) {fclose(fp);break;}
}
//fp=fopen("song1.wav","r");
//fp2=fopen("song2.wav","w+");
//rewind(fp2);
fseek(fp2,4,SEEK_SET);
fwrite(&newchunksize,4,1,fp2);//fprintf(fp2,"%c",&newchunksize);
//rewind(fp2);
fseek(fp2,40,SEEK_SET);
fwrite(&newsubchunk2size,4,1,fp2);
//rewind(fp2);
fseek(fp2,24,SEEK_SET);
fwrite(&newsamplingrate,4,1,fp2);
//fclose(fp);
fclose(fp2);
}
//Write data to file
void writedatafile(FILE *fp,int newsamplingrate,int newchunksize,int newsubchunk2size,int ratio)
{unsigned char down;
long int count=1;
int i=4;
FILE *fp2;
fp=fopen("mono.wav","r");
fp2=fopen("song2.wav","a+");
fseek(fp,44,SEEK_SET);
while(1)
{
fscanf(fp,"%c",&down);
fprintf(fp2,"%c",down);
count++;
i--;
if(feof(fp)) break;
if(i<1)
{
i=4;
fseek(fp,SEEK_CUR+4*(ratio-1)-1,SEEK_CUR);
}
}
fclose(fp);
fclose(fp2);
}
Monday, 14 December 2015
CMOS Buffer Using Two transistors
How to Analyse the Cmos Buffer With Two transistors
- This is one of the most prominent questions that is often asked in technical interviews of any electronics company.
- This circuit seems like it is very simple,but it if you start solving it it will lead to hell.
- In this post I will analyse this circuit and plot the VOUT vs VIN characteristics same as like the CMOS inverter.
- step1:
- Step2:
- Step3:
- Step4:
These Values will give you the input and output values that are being satisfyied by the circuit.
As it is very tuff to say intutively that which transistor will On and which will off for which values of input because those conditions will include the output voltage,I use MATLAB to get these graphs and intersections.
The Matlab Code is given Below:
clc;
clear all;
close all; vdd=5; up=500; un=1500; cox=3.28e-6; wbyl=2; wbylp=6; vtn=0.5;
vtp=-0.5;
vin=0:0.1:5;
vout=0:0.01:5;
lengthofvin=length(vin);
lengthofvout=length(vout);
for j=1:lengthofvin
for i=1:lengthofvout
if (vin(j)-vout(i)) < vtn currentn(j,i)=0;
end
if (vdd-vout(i))>(vin(j)-vout(i)-vtn)&& (vin(j)-vout(i))>=vtn
currentn(j,i)=0.5*un*cox*wbyl*((vin(j)-vout(i)-vtn).^2);
end
if (vdd-vout(i))<=(vin(j)-vout(i)-vtn )&& (vin(j)-vout(i))>=vtn
currentn(j,i)=un*cox*wbyl*(vin(j)-vout(i)-vtn-(vdd-vout(i))./2).*(vdd-vout(i));
end
end
end
for j=1:lengthofvin
for i=1:lengthofvout
if (vout(i)-vin(j)) < abs(vtp)
currentp(j,i)=0;
end
if (vout(i))>(vout(i)-vin(j)-abs(vtp))&& (vout(i)-vin(j))>=abs(vtp)
currentp(j,i)=0.5*up*cox*wbylp*((vout(i)-vin(j)-abs(vtp)).^2);
end
if (vout(i))<=(vout(i)-vin(j)-abs(vtp)) && (vout(i)-vin(j))>=abs(vtp)
currentp(j,i)=up*cox*wbylp*(vout(i)-vin(j)-abs(vtp)-((vout(i))./2))*(vout(i));
end
end
end
hold on; plot(vout,currentp','b');
xlabel('--------->vds');
ylabel('--------->ids');
title('Ids Vs Vds'); plot(vout,currentn','r'); hold off;
for j=1:lengthofvin
count=0;
for i=1:lengthofvout
if currentn(j,i)==currentp(j,i)
newinput(1,j)=vin(j);
if(vout(i)<=abs(vtp))
newoutput(1,j)=abs(vtp);
else if(vout(i)>=vdd-vtn)
newoutput(1,j)=vdd-vtn;
end newoutput(1,j)=vout(i); count=count+1;
if count==1 break;
end
end
end
end
end
for j=1:lengthofvin count=0;
for i=lengthofvout:-1:1
if currentn(j,i)==currentp(j,i)
newoutput1(j,1)=vout(i);
if(vout(i)>=vdd-vtn)
newoutput1(j,1)=vdd-vtn;
end
count=count+1;
if count==1
break;
end
end
end
end
figure; hold on;
plot(newinput,newoutput,'b',newinput,newoutput1,'b');
axis([0 5 0 5]);
xlabel('--------------->vin');
ylabel('--------------->vout');
title('Transfer Characteristics');
- The plot of the above MATLAB code will look something like give below:
So in the graph you can see that the intersection of the PMOS and NMOS curves for a particular value of VGS are the input and output voltages that will satisfy this circuit conditions.And from the above plot it is clear that we can see a lot of intersections between the PMOS and NMOS curves .So let us consider the average value of voltage between the first point of intersection and the last point of intersection between the two PMOS and NMOS curves for a particular value of VGS. Then we will get the input versus output characteristics as shown below.But still we have a confusion because we took an average intersection point .
If we take the first intersection point ,then we will get the characteristics like shown below:
Thursday, 28 May 2015
What is Cloud Computing
What is the cloud? Where is the cloud?
Are we in the cloud now?
One of the most important question that is often asked in an interview(IT company)
These are all questions you've probably heard or even asked yourself. The term "cloud computing" is everywhere.
In the simplest terms, cloud computing means storing and accessing data and programs over the Internet instead of your computer's hard drive. The cloud is just a metaphor for the Internet. It goes back to the days of flowcharts and presentations that would represent the gigantic server-farm infrastructure of the Internet as nothing but a puffy, white cumulonimbus cloud, accepting connections and doling out information as it floats.
What cloud computing is not about is your hard drive. When you store data on or run programs from the hard drive, that's called local storage and computing. Everything you need is physically close to you, which means accessing your data is fast and easy, for that one computer, or others on the local network. Working off your hard drive is how the computer industry functioned for decades; some would argue it's still superior to cloud computing, for reasons I'll explain shortly.
The cloud is also not about having a dedicated network attached storage (NAS) hardware or server in residence. Storing data on a home or office network does not count as utilizing the cloud. (However, some NAS will let you remotely access things over the Internet, and there's at least one NAS named "My Cloud," just to keep things confusing.)
For it to be considered "cloud computing," you need to access your data or your programs over the Internet, or at the very least, have that data synchronized with other information over the Web. In a big business, you may know all there is to know about what's on the other side of the connection; as an individual user, you may never have any idea what kind of massive data-processing is happening on the other end. The end result is the same: with an online connection, cloud computing can be done anywhere, anytime.
Total Pageviews
Labels
animation
ARM
ARM programming
Assembly programming
augmentedreality
authentication
Bag of Words
build module
CMOS
Companyprofile
computer vision
Cortex M4
CreaticeAssignment
cross build
Cross Compile
culture
embeddedsystems
Exponential Series
Facts
Fibonacci Series
five stage Pipeline
Floating Point
FPU
graphics
Hacking
Hazards
health
HowStuff
iiitb
imageClassifiaction
india
Innovation
Innovators
interview prep
interviewtips
kernel.img
Kmeans
KNN
LDAP
LDAPS
memory
Motivation
native compilation
natural
opencv
os
Pendrivefix
pipeline
pipelined processor
Projectideas.
protocols
python
raspberry pi
RealtimeCoding
Robotics
security
SIFT
Skill
soc
SURF
Technology
techstuff
tls
tutorials
vlsi
Watershed algorithm
writeback
Copyright ©
Learn Delta X | Powered by Blogger
Design by ManojKiran Eda | Blogger Theme by learndeltax