Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,799 members, 7,810,078 topics. Date: Friday, 26 April 2024 at 08:12 PM

Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl (2923 Views)

I Want To Develop A Software In Java To Calculate CGPA / What Topics To Cover In Java To Be A Guru? / Convert This Java To Dotnet Very Urgent (2) (3) (4)

(1) (Reply) (Go Down)

Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by geminititan: 9:17pm On Dec 14, 2010
As the summary says i'm using java to create a software to detect change in motion from what a usb webcam displays. Sort of like a security system.
I'm using a software from www.icaste.com for the webcam drivers. I've bin able to get the webcam's specifications like its vendor and product id, number of interfaces nd endpoints etc but the problem is reading the bytes of information that the webcam is sending to the computer. I managed to compile a program but it restarts my computer anytime i try to run it.

Pls i need help urgently because i have to be done with the project by next month!
Re: Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by kanirip: 9:19am On Dec 16, 2010
After checking the icaste website I have seen nothing to indicate that you can recieve your video stream from the Webcam using the provided drivers. I have read the Javadocs provided with the USB drivers and allI can see that 'MAY' allow for such is the readPipeIsochronous function. See below for the function description:

gemini_titan:

public int readPipeIsochronous(int iIntIndex,
                               int iEndpointIndex,
                               long lPacketSize,
                               long lFrameOffset,
                               byte[] baData,
                               int iArrayOffset,
                               int iNumBytes)
                        throws USBException
Read from Isochronous pipe. Read from pipe indicated to byte buffer provided. Data array is split up into packets of size lPacketSize. These packets are then read from USB bus isochronously starting at the current frame with offset lFrameOffset. If lFrameOffset is greater than MaxFrameOffset, the request is discarded. MaxFrameOffset can be found with getDeviceIsochronousFrameOffset(). Note, the current frame is calculated when the driver sends the request onto the bus. The actual current frame may have increased when the request hits the bus. If the offset places the request on a Frame that has already passed, the initial packets that belonged on the lost Frames will be discarded. If the offset places the request on a Frame that is yet to pass, the data will be delayed until it can be read from the correct frame. Method will block until all requested data is read, or Read/Write timeout expires. Use setReadWriteTimeouts() to adjust timeout settings.
Parameters:
iIntIndex - Interface index.
iEndpointIndex - Interface Endpoint index.
lPacketSize - Size of packet to be place onto each USB frame. The total requested data is divided into packets of this size.
lFrameOffset - Frame offset from current frame when this request hits the bus.
baData - Byte array for data.
iArrayOffset - Offset within baData to store the read data.
iNumBytes - Total number of bytes to read.
Returns:
Number of bytes read into array.
Throws:
com.icaste.JCommUSB_2_0.USBException - Thrown if OS encounters a problem or iNumBytes/iArrayOffset combination is outside baData bounds.

Send me an email on gmail__ AT __ kanirip.com ( switch the kanirip with the gmail) if you need any further assistance.[quote][/quote]
Re: Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by geminititan: 10:21pm On Dec 17, 2010
What do u do? Are u a professional programmer? I'm actually doing this for my big bro. He dosent have access to a computer right now and the project is driving him crazy.

He says " Thanks alot mehn. I already figured out dat was the method to use.

The problem now is using the right size of the byte array to place as a parameter in the method since the interface i'm using has several settings which have diferent maximum packet sizes. I dont know the size of the byte array that the pipe allows"
Re: Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by kanirip: 2:48am On Dec 18, 2010
I think what your brother needs to do is to choose a particular setting with a known maximum packet size, set the size of the byte array to that and then see how that affects the reading of the data stream from the USB bus.

Its not going to be simple but I fear that 'Trial and Error' is the route to use for such a task. It is what I would do.

Although from what I am reading in the Javadocs I don't think that the size of the byte array is really the problem, I feel that the Offset might be a bigger obstacle but this is just me. When you read from the USB bus, it will put as much as possible in the byte array.

What I'd recommend is that try creating a simple program that JUST reads the bytes using different settings and take it on from them, its called 'Divide and Conquer'.

Best of luck and let me know how it goes!
Re: Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by Zeta(m): 3:05am On Dec 23, 2010
Hey men. thanks for all your help. I was able to get bytes of information from the webcam.
I made the current setting 6 on interface 1. I then created a byte array of 1024. I used an offset of zero for the packet offset and a packet frame size of 64 in the readPipeIsochronous method.

The problem now is that the bytes of information change even if there is no motion over the camera's viewing area. Seriously. I'm not joking. This makes sense on some level because if you look closely at what a webcam views on your computer you will notice that color of some of the pixels constantly change.

Please I need your help again. Thanks for helping me this far. You could email me some good java books. Both for SE, ME or EE. My email address is efeariaroo4real@yahoo.com . Thanks again.
Re: Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by Zeta(m): 3:09pm On Dec 24, 2010
If you ever read this post. Please reply as soon as you can. Thanks
Re: Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by kanirip: 2:19am On Dec 27, 2010
Hi,

You should really mail me, I check my box way more regularly than I check Nairaland. I have my mailbox somewhere in the thread. Come to think I have been getting spammed a lot from ppl claiming to be from nairaland so maybe I need to modify the mail box so no bot can scan it.

As per your problem, what you need to do is probably find a way to get your byte array to a video display of some sort. Any clues? Apparently it has something to do with Java 2D. From my initial research it seems that you need to convert the byte array to an image , EVERY TIME YOU RECEIVE A FRAME from the webcam, changing or not. For the value in the byte array to change there must be something different in the captured from from the webcam. Image are liable to change at the slightest change in light or background images.

For Java 2D, you can go http://java.sun.com/developer/technicalArticles/GUI/java2d/java2dpart2.html

Sorry I can't send any books, they'll be simply too big.

Review and send me an email if you need additional assistance. If I don't reply, post your message here. I tend to delete any mails that has nairaland in it
Re: Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by Zeta(m): 7:41am On Dec 28, 2010
I was beginning to feel abandoned. Thaaaaaaaanks so much. I knew that light intensity had an effect, of course, but I didn't know it had that much effect. I thought the byte array values change because for real time audio or video from a USB port isochronous transfer is used. And with isochronous transfer there is always the possibility of data loss. I think your point is more along the lines of logic than mine.

I and my sister have been brain-storming trial and error algorithms to cater for this bytes values change. Algorithms like 'unless the number of changes in byte values is greater than 200 don't indicate that there's been motion' . All the algorithms failed. Some looked promising, but they were all flawed.

Thanks again. I'll get right on it. I'll let you know of my progress.
Re: Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by Zeta(m): 4:49am On Jan 03, 2011
@kanirip Hey there. I was able to create an image from the webcam(and even saved it to a jpg file), but I did it using the Java Media Framework. I've already written a program that those some pixel comparison, but the motion detector still fails. Could you suggest an algorithm to use to get this motion detector program done?

Thanks for all your help.
Re: Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by kanirip: 12:39pm On Jan 04, 2011
Hi there, I am pretty sorry to disappoint you but I am not a professional in Image procession ( did some Matlab image processing in Uni but that was pretty much it). But I have gone through the same process I would have gone through if I was developing the thing myself.

Firstly go here:
http://mindmeat..com/2008/11/java-image-comparison.html

It speaks mostly about the ideas required to perform this kind of Image comparison. Although it also discusses it with regards to Java, I think that you should strip your mind of the implementation details ( like the actual programming language used) and keep your mind on HOW the comparison was made. Like whether the image was broken down into smaller blocks before the checks were made and what not. Just check the steps basically.

Then go here:
http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx

This uses a different library to perform the exact same tasks that you are trying to accomplish. You can also learn the general ideas presented here and see what you can do similar yourself. You may also want to look into the library and see what its capable of doing and if possible HOW itr does it.

Then go here:
http://www.java2s.com/Code/Java/2D-Graphics-GUI/AmotiondetectionalgoritmforusewiththeJavaMediaFrameworkAPIJMF.htm
This is actually what you want , but hopefully if you understand the ideas very well then you can go ahead and improve what is being presented in this code snippet.

Ok so, look into the pages and let me know if you need any additional assistance.

Best of luck.
Re: Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by Zeta(m): 4:39pm On Jan 05, 2011
Thanks so much. Just like you said, that last link was exactly what I needed. What I'll do now is to understand the code, then create a simple GUI for it, and to add an alarm sound. My work is about fifty percent complete. Thanks again.
Re: Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by a3cube: 12:25am On Jan 06, 2011
codeNIGERIA.com - The Nigerian developers forum. Just ask your question.

http://codenigeria.com
Re: Does Anyone Have Tips On Using Java To Interact With A Usb Device? Its For My Final Year Project. Pl by kanirip: 12:33pm On Feb 03, 2011
Hello Zeta,

How is this project going?

Keep me in the loop. Thanks.

(1) (Reply)

Have An App Idea? Let's Build Your Next App / Import Dll Into Java Program / Nigeria First Free And Open Source Education Software

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 34
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.