Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Friday, 27 October 2017

Sunday, 2 April 2017

Generating Permutation in Python

This is the best way to generate permutations in python.

from itertools import permutations

j="1234"
for i in permutations(j):
    print "".join(i)


Thursday, 30 March 2017

FAD-Facial Age Determinator

FAD - Facial Age Determinator is a Python based software to determine the age of people using skin texture. It determines the age group of people and classifies them into 4 groups, kids(1-10), young(10-25),adults(25-50),seniors(51+).

Applications

  • Vending Machines for cigarettes and beer
  • Age Appropriate Advertisements
  • Targeted Advertisements on Bill Boards
  • Age Restricted Entry Zones(Bars, Adult Cinema)
  • As a filter in other Facial Processing Systems
  • Human Robot Interactions
  • Smart Car System Adaptive Behavior(Determining whether to apply brakes based on age group of pedestrian crossing.)
  • Elderly Assistance Systems
  • Enhanced Security for Kids Only Zones etc 

Implementation Details

Sunday, 26 March 2017

The Fastest and Easiest Way to Install OpenCv for Python on Ubuntu

Python burning gif
When I first installed OpenCV I used an article on which installed opencv from source. However this is unnecessary and time consuming.

The entire process is too complicated. You will need to use that process only if
  1. You are using the latest OpenCV features
  2. You need Python 3 bindings
Before building from the source I highly recommend you trying the method described in this post. It is quick and simple.

Saturday, 25 March 2017

Persistance in Python

Recently I was training a dataset for Facial Age Determination. A considerable amount was spent each time I launched my script.

The Reason: It was retraining the whole dataset at each launch.

Solution : Saving the dataset into a file loading it back.


Serialization in Python


Serialization allows you to save objects to a file and reload them. I have worked with Java and Python Serialization, and with python its a piece of cake.

There are two options

  1. Pickle
  2. CPickle
You usually would want to use cpickle as its faster. It can be over a thousand times faster.

I would be thus demonstration cpickle store and load through this post. The steps for pickle are the same. Just import pickle instead of cpickle and you are good to go.


Thursday, 23 March 2017

Feret Database PreProcessing Script

I am currently working with the Feret Database on Age Determination using Frontal Facial Images using KNN and LBP in Python 3 and OpenCV.

However the Feret Database comes in a tar which when extracted contains a large number of ppm files in bz2 archives which need to be converted into jpegs before any further processing can take place.

I wrote this script in case. I am sure it will be useful to other people working with the Feret Database.

Thursday, 12 January 2017

Simulation of Lift Using Led, Switches and Beagle Bone Black

Introduction

This is a simulation of working of lift using beagle bone black and python. The position of lift will be indicated using led. Switches will be used as lift buttons.

Wednesday, 2 November 2016

Print the number of substrings which are a Palindrome

Q: Given an input string, find out the number of substrings for the given strings which are palindromes.





Solution Strategy : Brute Force
Language : Python


Wednesday, 7 September 2016

Identify Mobile Operating System using Python and ADB


Q:Write a Python/Java/C+ program to verify the operating system name and version of Mobile devices.


Note: This program will only work for android devices. (Since Iphones do not have anything equivalent to adb. )No wonder android is the favorite platform when it comes to app development. Android market is also more developer friendly as compared to its ios counterpart.

Errors: In case you get an error about insufficient permission, either edit udev rules or borrow a phone from your friend, having a well known global manufacturer.

OS:Fedora 20 64 bit
Phone: Sony Xperia
Language: Python
Dependencies: Just adb package,No need for sdk
fedora:               <yum install adb>
ubuntu:              <apt-get install adb>

Friday, 26 August 2016

Use Python for Socket Programming to connect two or more PCs to share a text file.

Os: Fedora 20
Network: Switched LAN(Ethernet)

Note: Program fails to work on Local Area Network. Program works flawlessly on localhost.

While this script works perfectly fine on loop back ie on the same machine, it fails on networks.For some unknown reasons I havent' been able to get this script running of a local network consisting of fedora linux machine despite tweaking with the firewall. I don't get much time to work on local networks and am currently busy with some other endeavors. 

Write an IPC program using pipe using C++ and Python

Q: Process A accepts a character string and Process B inverses the string. Pipe is used to establish communication between A and B processes using C++ & Python

Write a program in Python/C++ to read display the i-node information for a given text file, image file.

Code

 

 

Monday, 11 July 2016

Python Script to Recover Deleted Files And Partitions

Ever deleted a file permanently and wished to recover it. Here's a python script designed to do this task in Linux operating system.

Tuesday, 21 June 2016

Python Based Chat Program

This is a simple client-server Program to chat with other users on the Lan. This program largely similar to a chat using nc, easier to use and with a lot of less functionality.

Tested On:
OS: Fedora 20, Ubuntu 14.04 LTS
Language: Python

 Note

While this script works perfectly fine on loop back ie on the same machine, it may fail on a network since you might need to configure the server to accept incoming connections. You might want to check iptables or disable it completely. 

Video

Monday, 20 June 2016

Email Header Analyser Using Python

Q:Write a program in Python to analyze email header.

This program simply analyzes a email header stored locally on your machine in a text file and shows information like:
  1. Mime Version
  2. Date
  3. Subject
  4. From
  5. Delivered To
  6. To
This is nothing but a simple file handling and string matching problem. And to make it look insanely simpler, I decided to write the code with the minimum number of lines, and guess what I did manage it in just 15 lines. I did have to remove the exit messages though.

Monday, 1 February 2016

Powerset Generator Recursive Algorithm Python

 Q:Write a python program to generate powerset for given set of elements.

Truth Value Generator-Recursive Algorithms-Python

Q:- Write a Python Program to generate all possible truth values for a given number of boolean variables

Tower of Hanoi-Solution

python-tower-of-hanoi The Game

Tower of Hanoi is a puzzle game. Your objective is to move disks from one tower to another tower. You initially have 3 towers of which two are empty and one(say tower 1) contains n disks. These n disks are all of different sizes. In tower 1 they are present in definite order- the largest at the botttom and the smallest at the top. You can only move one disk at a time. The rule is that you cannot place a bigger disk on a smaller disk. This relocation of disks needs to be done in minimum number of moves.

Monday, 14 December 2015