Chrome Pointer Harshavardan61: Tech
Showing posts with label Tech. Show all posts

Wednesday, December 18, 2013

Basic Image Processing Using Raspberry Pi

Basic Image Processing

Difficulty: beginner

This tutorial aims to be a basic introduction to image processing with the Raspberry Pi and Python. We will write a Python script to grab webcam images, which we will then alter and display. In later tutorials we will look at more complicated functionality, and the use of more peripherals and a robot.

REQUIREMENTS:






You may also need an Internet connection in order to download libraries.

INSTRUCTIONS:

If you are not using one of our SD cards or images, then please install our custom libraries.
To begin the tutorial, start up a text editor and create a new file called “basic.py”; we will use this script as a test bed to try out the image processing library. Alternatively, you can use the interactive Python environment to test the code as you go along.
The first thing our Python script needs to do is import the image processing library. So enter
from imgproc import *
at the top of the script or into a interactive Python session. This loads and sets up the library read for use.
The imgproc module provides us some basic functionality to use a webcam, access image data and display images on screen, as well as some higher level image processing functions we will use later.
We’ll begin by opening the camera device. Enter this next, on the next line beneath the import statement
my_camera = Camera(320, 240)
This opens the camera device, setting the size of the captured images to 320 pixels width by 240 high.
On its own this statement doesn’t do a great deal: we’ve opened a Camera but don’t actually do anything with it, so let’s grab an image from the camera and store it.
my_image = my_camera.grabImage()
Now we have an image, so as a final step let’s display it on screen. First we must open a viewer window, and then we need to tell the viewer to display the image we capture. Finally we add a delay, to give us time to see the image (not necessary from the interactive session).
# open a view setting the view to the size of the captured image
my_view = Viewer(my_image.width, my_image.height, "Basic image processing")

# display the image on the screen
my_view.displayImage(my_image)

# wait for 5 seconds, so we can see the changes
waitTime(5000)
Your complete code should now look like this:
from imgproc import *

# open the webcam
my_camera = Camera(320, 240)
# grab an image from the camera
my_image = my_camera.grabImage()

# open a view, setting the view to the size of the captured image
my_view = Viewer(my_image.width, my_image.height, "Basic image processing")

# display the image on the screen
my_view.displayImage(my_image)

# wait for 5 seconds, so we can see the image
waitTime(5000)
Now run your code from the terminal with the command
python basic.py
There will be a delay as the camera loads up and grabs an image. Afterwards you should see the image appear in a new window.
Now we have the basic setup, we can start playing with the image data.
The image data is a 2 dimensional array of pixels, and each pixel is a tuple of 3 values: the relative intensity of the red, green and blue colours in the range 0 to 255 (inclusive). You can access a given pixel in the image by treating the image as an array, and by providing a tuple of the x and y position of the pixel.
# get the value of the pixel at x position 120 and y position 64 in the image
pixel = my_image[120, 64]
# pixel is now a tuple of the red, green and blue of the requested pixel

# An alternative method
red, green, blue = my_image[120, 64]
# red, green and blue now contain the intensity of the red, green and blue
# channels respectively
To set the value of a pixel, you assign a 3-tuple to the position, beware you can only set values to between 0 and 255 (inclusive).
# Set the value of pixel at x position 120 and y position 64 
# to an orange colour
my_image[120, 64] = 255, 128, 0
Now as a use of this functionality, we will take every predominantly red pixel in the image and change it to blue. Here is some commented Python code which will do this.
# iterate over ever pixel in the image by iterating over each row and each column
for x in range(0, my_image.width):
  for y in range(0, my_image.height):
    # get the value of the current pixel
    red, green, blue = my_image[x, y]

    # check if the red intensity is greater than the green
    if red > green:
      # check if red is also more intense than blue
      if red > blue:
      # this pixel is predominantly red
      # let's set it to blue
      my_image[x, y] = 0, 0, 255
To run this code, place it in the script after we grab the image from the camera. Make sure you also put it before the image is displayed to the screen, otherwise it will only be altered after it has already been copied to the display.
This signals the end of this first basic tutorial. From here you may like to move onto the more advanced tutorials, or experiment with the code you have. There is also a listing of all of the functions in the Python module, if you just want to play around. The interactive interpreter is a good way to get familiar with the functions.
Keep in mind when accessing pixels that you need to grab an image from the camera before using it, and if you set the colour of pixels, you need to display the image afterwards to see the change on screen.
Read More

Thursday, September 5, 2013

Interfacing Bi/Uni Polar Stepper Motor to a mbed Microcontroller Using L293D


Interfacing Bipolar stepper motor with L293D and mbed Micro controller(LPC 11U24)
Connect the pins 2,7,10,15 (IN1, IN2, IN3, IN4) of L293D to the ports 9,10,11,12 of the mbed board.
Connect the pins 4, 5, 12, 13 to ground.
Connect the enable pins 1,9 (EN1,EN2) to a 5V supply(or) port 39 of mbed board .
Connect the pin 16 to +5V. It is the power supply of the chip.
Connect the pins 3, 6, 11, 14 to the four pins of the bipolar motor.
Connect the pin 8 to +12V/+9V.It is power supply for motor.




Get the code for interfacing the stepper motor with the mbed board using the L293 
driver visiting the following link
Read More

Tuesday, August 27, 2013

How can I root my Android device?

Rooting Android devices using packages from F-Droid

There are several ways of rooting Android devices and there is no universal method, but if there are no measures taken by the manufacturer, chances are not that bad to get root by following the instructions below. Following this guideline, only packages from F-Droid will be pushed to your device. Keep in mind that we can't provide assistance for specific devices.
Everything is on YOUR OWN RISK! We are not responsible, if your device doesn't work or has some malfunctions. Also read "Should I root my device?".
Before you go on, enable Unknown Sources and USB debugging on your device:
  1. Menu -> System settings -> Security -> Unknown Sources -> Enabled
  2. Menu -> System settings -> Developer options -> USB debugging -> Enabled
Download and install 7-zip, download and install Android SDK, download OEM USB Drivers, download Google USB Driver, download Superuser and Terminal Emulator App.
Depending on your phone OEM USB Drivers or Google USB Driver may work. Often you have to install device specific drivers, provided by the manufacturer of your device. Install the appropriate driver to get ADB access over USB.
Rename org.fdroid.superuser*.apk to org.fdroid.superuser*.zip .
Extract org.fdroid.superuser*.zip with 7-zip or a similar program.
Copy "su" from org.fdroid.superuser_*\assets\armeabi to the folder from where you execute your ADB, on Microsoft Windows likely C:\WINDOWS\Android\android-sdk\platform-tools, depending on the path selected while installation. In case you can't find it, search for "adb.exe".
Open your shell (CMD.exe on Windows, e.g. Bash on Linux) and change directory to your ADB folder and type:
  1. adb kill-server
  2. adb root
  3. adb remount
  4. adb push su /system/xbin/su
  5. adb shell
  6. chown 0:0 /system/xbin/su
  7. chmod 6755 /system/xbin/su
  8. ln -s /system/xbin/su /system/bin/su
  9. adb reboot
Copy org.fdroid.superuser*.apk to the SD-card of your Android device and install it.
Copy jackpal.androidterm_53.apk to the SD-card of your Android device and install it.
Open "Terminal Emulator" on your Android device and type "su", then permanently allow root if a # appears in the beginning of the line, you now have root.
Note: Busybox is not in the F-Droid repository so far, thus we provide no link. You can try whether Busybox is already on the device by typing "busybox" in Terminal Emulator. It should give you a long list of commands, if it is installed.

Read More