Mobile phone library to read 1D and 2D barcodes
(MQR – LIBRARY)
Two prove that the library is working, two applications will be developed for identify people (1D) and another one for read medical recodes (2D).
· Reusable open source library or API for mobile application development.
· There are no open source library for this purpose and only have few commercial ones only and the community can do the enhancements of the library.
· When this come to the mobile phone community the people can develop their applications in very fast and easy way.
· sample apps r only to show it works
· Another aim to evaluate how image processing algorithms perform in mobile phones and the feasibility of implementing image processing algorithms in mobile phones.
· Decoding 2D barcodes – decrypting encrypted information in 2D code.
· Java (can support different phone models) and try to use only the phone for this as much as possible.
· Stand alone library to identify 1D barcode (can use in other applications such as security checkups, super markets, mobile sales, effective advertising)
This is the code segment for capturing and decoding/generating the pixcel data across the middle of the captured barcode.
************************************************************************************************
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javax.microedition.midlet.*;
import java.io.IOException;
import javax.microedition.amms.MediaProcessor;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Gauge;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.Graphics.*;
/**
* @author Administrator
*/
public class CamaraTest extends MIDlet implements CommandListener {
private Form formInfoByPicture;
private Player vedioPlayer;
private VideoControl videoControl;
private Item videoItem;
private Display display;
private Display displayLine;
private Graphics g;
private Command capture;
private Command go;
private Command uploadCommand;
private Command backCommand;
private Command exit;
private Command backToCamCommand;
private Form sendImageForm = null;
private Form UploadImage = null;
private byte[] snapshot;;
private byte[] uploadData;
private int imageCount ;
private Form SplashScreen;
Image img;
Graphics gg;
int[] intImage;
// private Gauge gauge = null;
private Gauge gauge=null;
public void startApp() {
display = Display.getDisplay(this);
splashScreen();
// getFormInfoByPicture();
}
public void splashScreen()
{
if(SplashScreen==null)
{
SplashScreen =new Form("");
// SplashScreen.append("/logo.png");
try{
img = Image.createImage("/code.png");
// img=Image.createImage(SplashScreen.getWidth(), SplashScreen.getHeight());
// img.createImage(img, 0,0,100,50,1);
//img.createImage(SplashScreen.getWidth(), SplashScreen.getHeight());
}catch(Exception e){}
// SplashScreen.append(img);
SplashScreen.append(resizeImage(img));
SplashScreen.addCommand(go);
SplashScreen.addCommand(exit);
SplashScreen.setCommandListener(this);
display.setCurrent(SplashScreen);
}
}
public CamaraTest() {
go = new Command("Go", Command.EXIT, 0);
capture = new Command("Capture", Command.SCREEN, 1);
backCommand = new Command("Back", Command.EXIT, 0);
exit = new Command("Quit", Command.EXIT, 0);
uploadCommand = new Command("Upload", Command.SCREEN, 1);
backToCamCommand = new Command("Back", Command.EXIT, 0);
}
private Image resizeImage(Image src) {
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
int screenWidth=SplashScreen.getWidth();
int screenHeight=SplashScreen.getHeight();
Image tmp = Image.createImage(screenWidth, screenHeight);
Graphics g = tmp.getGraphics();
int ratio = (srcWidth << pos =" ratio/2;" x =" 0;">> 16), 0, Graphics.LEFT | Graphics.TOP);
pos += ratio;
}
Image resizedImage = Image.createImage(screenWidth, screenHeight);
g = resizedImage.getGraphics();
ratio = (srcHeight << pos =" ratio/2;" y =" 0;">> 16), Graphics.LEFT | Graphics.TOP);
pos += ratio;
}
return resizedImage;
}//resize image
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void getFormInfoByPicture() {
if (formInfoByPicture == null) {
// capture = new Command("Capture", Command.SCREEN, 1);
formInfoByPicture = new Form("");
formInfoByPicture.addCommand(backCommand);
formInfoByPicture.addCommand(capture);
formInfoByPicture.setCommandListener(this);
// g.setColor (0, 0, 123);
// g.fillRect (20, 30, 200, 80);
// display = Display.getDisplay(this);
}
new Thread(
new Runnable() {
public void run() {
try {
vedioPlayer = Manager.createPlayer("capture://video");
vedioPlayer.prefetch();
vedioPlayer.realize();
videoControl = (VideoControl) vedioPlayer.getControl("VideoControl");
videoItem = (Item) videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null);
int width = formInfoByPicture.getWidth();
videoControl.setDisplaySize(width, width);
formInfoByPicture.append(videoItem);
vedioPlayer.start();
} catch (Exception e) {
System.out.println(e.toString());
}
}
}).start();
display.setCurrent(formInfoByPicture);
// Canvas canvas = new canvasLine();
// display = Display.getDisplay(this);
// display.setCurrent(canvas);
}
private byte[] getSnapshot() {
sendImageForm = new Form("SEND FOR VERIFIACATION");
gauge = new Gauge("Progress:", true, 100, 0);
sendImageForm.addCommand(uploadCommand);
sendImageForm.addCommand(backToCamCommand);
sendImageForm.setCommandListener(this);
new Thread() {
public void run() {
try {
snapshot = videoControl.getSnapshot("encoding=jpeg");
uploadData = snapshot;
if (snapshot != null) {
Image image = Image.createImage(uploadData, 0, uploadData.length);
ImageItem imageItem = new ImageItem("", createThumbnail(image), Item.PLAIN, "");
intImage = new int[image.getWidth()];
image.getRGB(intImage, 0, image.getWidth(), 0, 5, image.getWidth(), 1);
int[] pixelData ;
pixelData=new int[getGrayData(intImage).length];
pixelData=getGrayData(intImage);
int rgbValue;
for( int i = 0; i < rgbvalue="pixelData[i];" astring =" Integer.toString(rgbValue);//.substring(3);" sourcewidth =" image.getWidth();" sourceheight =" image.getHeight();" thumbwidth =" 96;" thumbheight =" -1;" thumbheight ="="" thumbheight =" thumbWidth" thumb =" Image.createImage(thumbWidth," g =" thumb.getGraphics();" y =" 0;" x =" 0;" dx =" x" dy =" y" immutablethumb =" Image.createImage(thumb);" c ="="" forminfobypicture =" null;" c ="="" forminfobypicture =" null;" c ="="" splashscreen =" null;" c ="="" sendimageform =" null;" c ="="" sendimageform =" null;" c ="="" sendimageform =" null;" uploadimage =" new" graydata =" new" grayvalue =" 255;" j=" (imageARGBData.length">= 0 ; j--){
//(r + g + b)/3
grayValue = (((imageARGBData[j] >> 16) & 0x00FF) +((imageARGBData[j] >> 8) & 0x0000FF) + (imageARGBData[j] & 0x000000FF));
grayValue = grayValue / 3;
grayData[j] = grayValue ;
}
return grayData;
}
}
************************************************************************************************
No comments:
Post a Comment