| Reply | « Previous Thread | Next Thread » |
|
Is it possible to capture a raw video stream from nokia 3650 / 7650.
I have read in posts that symbian applications can do it (they capture the stream and compress to mpeg) but is it possible with Java? Is it possible to obtain a bytearrayinputstream using a locator like: capture://video?encoding=gray8&width=160&height=120 as described in the MIDP 2.0 MMAPI doc: http://bf.monis.ch/prog/java/midp/midp-2-mmapi/ In the case it's not (Which I fear) what's the format of the BMP the getsnapshot() method returns? Does it use any compression or is ia a plain rgb file with a simple header I can just skip? Finally, about speed. If I have to use the latter method would you consider possible on a 3650 or 7650 to capture at 15 fps using a loop of getSnapshot(). ? BTW, I do not intend to display or keep the image anywhere, just capture it, analyze it's pixels and trash it. Thanks for your help! |
| blackjack75 |
| View Public Profile |
| Find all posts by blackjack75 |
|
Did anybody ever do this ?
|
| blackjack75 |
| View Public Profile |
| Find all posts by blackjack75 |
|
I had the same problem when trying to convert a midp2.0 application (for a 6600) to midp 1.0 for a 3650. In Midp2.0 we have the Image.getRGB() method, wich returns an array of ints with the RGB values of the pixels.
As you know, this does not exist in midp1.0, so I had to implement myself something of the like. What I did is get a byte array with the png image with getSnapshot(null), And then obtain the pixel values from there. This is quite easy as, fortunately, the image returned by the camera (not by the simulator, which returns just the image as you put it, as you know) is neither compressed, interlaced nor filtered, so all I had to do was take the headers out. Well besides of the png header, we have a deflate header at the beginning of every scanline of the image (a Png-format image contains zip-format data, with contains deflate-format data. Don´t worry, as I said above, nothing is compressed, it´s only headers. It is all documented at www.libpng.org), and also the byte for the filter of the line. Just ignore this and get the pixel values. It´s a clumsy solution, but it works. You may find all the information about png format at www.libpng.org, but better, try first with the bmp format with getSnapshot("encoding=bmp"), this may be simpler (I thought of this after I had finished with the method in png format...). |
|
Hi JTierno,
thanks for your help. We'll get on it then! How many fps do you get with the such technique (skipping the headers) ? Yup, I thought about BMP rather than png since it is indeed much simpler. I suspect the phone can do snapshots at a decent speed with this. Do you think it is possible to call getSnapshot() at about 15 fps on a 3650? Or is it hopeless? Thanks for your help |
| blackjack75 |
| View Public Profile |
| Find all posts by blackjack75 |
|
Sorry, I don´t know much about speeds, as my application is not real-time. I just get an image on user´s demand and process that single image.
But I don´t think it is hopeless, I´d give it a try. Good luck. |
|
Hi,
I am taking a snapshot from Nokia 3650 and storing it in the BYTE array. I have the following doubts :- 1) is the data in the BYTE array COMPRESSED ? 2) Will EACH LINE of PNG image have HEADERS ? because I visited the www.libpng.org and there they said that ALL DATA is between the IDAT & IEND header chunks. is this information correct ? Kindly do clear my doubts. Hoping to hear from you. Yours Sincerely, Sunil Manoharan |
| manohsunil |
| View Public Profile |
| Find all posts by manohsunil |
|
I have replied this already by mail, but in case somebody else is interested.
The data is all contained in one only IDAT chunk, but each scanline is packed inside its own Deflate block, So every line has a header (And also a filter byte). However, the data block is not compressed: The deflate header indicates zero compression. Here is the code I use to extract the rgb values of an image. I extract the fields of the header one by one, but do nothing with them, just skip: void getRGB(byte in[], int out[]){ int chunklen; byte fourbytes[] = new byte[4]; DataInputStream stream = new DataInputStream(new ByteArrayInputStream(in)); int offset = 0; int width=0,height=0; String chunkName = null; StringBuffer sb; try{ //read PNG sign stream.skip(8); while( true ){ //length chunklen = stream.readInt(); if (chunklen < 0) throw new IOException("Parsing Exception reading chunk length"); //type if ( stream.read(fourbytes) == -1) throw new IOException("Parsing Exception reading chunk type"); chunkName = new String(fourbytes); // Data //IHDR: first Chunk if (chunkName.equals("IHDR")){ width = stream.readInt(); height = stream.readInt(); if (width*height != out.length) throw new IOException("sizes do not match:"); if (stream.readByte() != 8) throw new IOException("bit depth not supported"); byte b = stream.readByte(); //compression b = stream.readByte(); //filter method b = stream.readByte(); //Interlace method b = stream.readByte(); } //IEND: last Chunk else if (chunkName.equals("IEND")){ //System.out.println("IEND chunk!"); break; } //IDAT: image data else if (chunkName.equals("IDAT")){ System.out.print("IDAT chunk... "); stream.read(data,offset,chunklen); offset += chunklen; } //Any other chunk is not parsed: skip data else if (stream.skip(chunklen) != chunklen) throw new IOException("Parsing Exception reading unused chunk"); //CRC if(stream.skip(4) == -1) throw new IOException("Parsing Exception reading CRC"); } stream.close(); //Read data inside IDAT Chunk stream = new DataInputStream(new ByteArrayInputStream(data)); //Code stream.readByte(); //flags stream.readByte(); //Deflate header stream.readByte(); byte header; int len, nlen; byte filter; //Read each scanline for (int i = 0; i < height; i++) { header = stream.readByte(); if ( (header & 6) != 0) { throw new IOException("incorrect deflate header"); } if (i == height-1 && (header & 1) != 1) { throw new IOException("incorrect last deflate header"); } len = (int)stream.readUnsignedByte()+256*(int)stream.readUnsignedByte(); nlen = (int)stream.readUnsignedByte()+256*(int)stream.readUnsignedByte(); //LEN & NLEN header fields if (len + nlen != 65535){ form.append("\nLEN: "); form.append(new Integer(len).toString()); form.append("; NLEN: "); form.append(new Integer(nlen).toString()); throw new IOException("nlen != one´s complement!"); } //Filter type filter = stream.readByte(); if (filter != 0) { form.append("\nFIlter: "); form.append(new Byte(filter).toString()); throw new IOException("filter present"); } if (width != (len-1)/3) throw new IOException("Incorrect width"); for (int j=0; j<width; j++) { out[width*i+j] = ((int)stream.readUnsignedByte())<<16 | ((int)stream.readUnsignedByte())<<8 | (int)stream.readUnsignedByte(); } } //ADLER 32 checksum. if (stream.skip(4) != 4) throw new IOException("Incorrect Checksum"); stream.close(); } catch(IOException ioe){ System.out.print("IOException: "); System.out.println(ioe.getMessage()); } } I hope this is of some help. |
|
When give do this :
getSnaphot(encoding=gray8) I take some Exception Question : how can i get an image with gray8? |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|