Hi all! First I want to thank in advance anyone who helps and say that I am aware that this is NOKIA forum.
I use SE K310, MIDP 2.0, CLDC 1.1.
My goal is to:
1.image1 = getSnapshot from camera
2.wait 200ms
3.image2 = getSnapshot from camera
4.process 2 previously captured images to see if they are different
5.if threy are different - exit the loop and draw the 2nd image - if not, continue to loop
Below is partial code I use, but sometimes it restarts the phone, sometimes goes very slowly.
I am not sure if I use the newly created thread correctly and wonder if something needs to be synchronized?! Or is this in general the right way to go about?!
How can I speed up things?
The CaptureCanvas is set on display externaly with:
Code:captureScreenCanvas.start(); display.setCurrent(captureScreenCanvas);
Code below has been striped for null value checking and try-catch blocks.
In short, all I want to do is capture images(in loop) on Sony Erricsson k310 and stop if they are different.Code:public class CaptureScreen extends Canvas implements Runnable{ //... //...various variable declarations and initializations, constructor... //... public void start(){ quit = false; initPlayer(); Thread CaptureThread = new Thread(this,"DT"); CaptureThread.start(); setFullScreenMode(true); } public void run(){ int[] Data1=null; int[] Data2=null; while(!quit){ capturedImage1 = captureImage(); //capture no.1 Data1 = makeData(capturedImage1); //change 1st into array of integers(pixels) Thread.sleep(300); capturedImage2 = captureImage(); //capture no.2 Data2 = makeData(capturedImage2); //change 2nd into array of integers(pixels) quit = differentData(Data1,Data2); //see if images are different } stop(); repaint(); } private Image captureImage() { byte[] imageData = null; Image img = null; imageData = vc.getSnapshot("encoding=jpeg&width=120&height=160"); img = Image.createImage(imageData, 0, imageData.length); return img; } protected void paint(Graphics g){ if ((capturedImage2!=null) && quit){ g.drawImage(capturedImage2, 0, 0, 0); } } public void initPlayer() { playerVideo = Manager.createPlayer("capture://video?encoding=jpeg&width=120&height=160"); playerVideo.realize(); playerVideo.prefetch(); if ((vc = (VideoControl) playerVideo.getControl("VideoControl")) != null) { vc.initDisplayMode(vc.USE_DIRECT_VIDEO, this); vc.setDisplayLocation(0, 0); vc.setDisplayFullScreen(false); vc.setDisplaySize(120, 60); } playerVideo.start(); } private int SingleColorThreshold = 15; private int Step = 10; private int ThresholdCount = 1000; // check if RED channel difference in every 10th(Step) pixel between 2 images is greater the SingleColorThreshold // if 2 pixels are recognized as different then increase the counter // run the for loop as long as counter is less than ThresholdCount public final synchronized boolean differentData(int[] Data1, int[] Data2) throws IOException { count = 0; boolean temp = false; for (int i = 0; i < Data1.length; i += Step) { if (java.lang.Math.abs(((Data2[i]>>16) & 0xff) - ((Data1[i] >> 16) & 0xff)) > SingleColorThreshold) { count++; } if(count>ThresholdCount){ temp=true; break; } } return temp; } private int[] makeData(Image img) { int[] DataTemp = null; DataTemp = new int[img.getWidth() * img.getHeight()]; img.getRGB(DataTemp, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight()); return DataTemp; } public void stop() { vc = null; playerVideo.stop(); playerVideo.close(); playerVideo = null; playerSound.close(); playerSound = null; } }
I havent figured it out what encodings are for setting gray capturing. I belive the device is capable of capturing in gray through j2me because there are options for gray capturing when using phones own camera software.
I would appreciate if anyone could help me with this or at least give me some pointers and information. Thank you!

Reply With Quote

