Here’s a potential media application. Can Flash or one of the Java media libraries handle it?
One of the weaknesses — and I’m surprised by the lack of critical talkbacks, c’mon people, this is a blog, where’s the hate? — of my little Java Media trilogy (viz., acts I, II, and III), is that after a point, I expect the reader to take on faith my claim that Web 2.0’s read/write nature will eventually express itself in media, and that we’ll need media frameworks that offer more than just playback. So, I’d like to propose an application and go about seeing how feasible it is.
The key to my current line of thinking is that I want to get in the mindset of the application developer who knows she’s doing a media application, but doesn’t yet know which languages, libraries, or platforms to choose. This is different than the usual mindset of “we’re all Java programmers, what do we want in a media library?” I think it’s important to understand what advantages, if any, a Java approach offers.
Starter deck
The idea for this application comes from the fact that I’m interested in learning more about trading card games, specifically the Fullmetal Alchemist TCG. It looks interesting, and the designers seem to really get the show.
Thing is, these games have a real network effect to them — popular games have more players to enjoy the game with, more places to buy cards, etc. If you like something nichey, say, the Battlestar Galactica game or the City of Heroes game (or FMA, for that matter), instead of popular war-horses like Yu-Gi-Oh or Magic: The Gathering, then you’re going to be hard up to find opponents.
Obvious solution: go online. The internet is all about niches. And this can work, but then again, why bother being a card game if it’s gonna be an online computer game? At that rate, you might as well play an online RPG.
But somehow, I got to thinking… I guess it was the idea of Delicious Monster turning my iSight into a bar-code reader.
So, imagine if every card manufactured had a universally unique ID number, represented as a bar code on the card itself. This would allow an online version of the game to be played with your physical deck, simply by scanning your cards with your webcam as they’re played. Something like this (but not as cheesily fake):
Since the online version would work with physical cards, it would encourage the continued sale of physical decks, cards, and accessories, and help titles achieve a network effect by connecting players to one another. You could probably sell some Google ads on the site too, just to make it even more appealing to management. Maybe we’ll throw in optional voice and video chat so the players can socialize.
There are lots of implementation details that can be discussed (how to prevent counterfeiting, whether tracking players by their cards is incompatible with real-world trading, etc.), but that’s not my point. My point, firstly, is to get this up as prior art just in case this Method of Associating Collectible Gaming Cards with Online Records by Means of a Video Capture Device isn’t patented yet. (^o^)
But my main point is this: if you are Mr. Trading Card Company, what technology do you use to implement this?
Discard Pile
My guess is that most developers would start by looking at Flash, because they’re probably already using it for their website (such as, say, the online tutorial for FMA). Flash has the advantage of being the only web-centric Win/Lin/Mac solution that supports video capture. Here’s a short step-by-step on setting up a basic camera preview as part of a Flash presentation.
The problem with the Flash approach is that there doesn’t seem to be a straightforward way to get at the pixels, which you would need in order to run an algorithm to find and interpret the barcode (I’m taking it on faith that such an algorithm can be developed from available resources on bar-codes, or licensed from a subject-matter expert). Neither the Camera nor the Video ActionScript objects seem to have calls to get the pixels from the camera.
This might be possible with Java Media Framework. I don’t remember all the details of JMF anymore, but I think you would need to construct a plug-in like a Codec (I think?) that would get an opportunity to have its process() method called with captured frames from the camera. It’s in this call that you’d have access to the camera’s pixels, and be able to run your barcode-finding logic. Thing is, with JMF, while your code might compile, nothing’s really promised at runtime: you might or might not be able to get a Processor to use with the discovered capture device. And the list of supported capture devices does not inspire confidence, considering that Windows compatibility is listed entirely in terms of deprecated version of the OS (98, NT, etc.). Plus, the JMF solution only works on Windows — if you’re going to write a one-platform application, you might just skip the webapp (and Java) and write a native desktop application.
QuickTime for Java would definitely work, something I can say with confidence after working extensively with its capture API in the last year (I wrote a minimal-hassle, compress-as-you-go, actually-has-a-preview-window video capture app for Veldhiezen Group, who are really into QuickTime and were great to work with). For the card game app’s scanner, you’d create an SGDataProc object that would get called back every time the “Sequence Grabber” has new data. The callback includes a pointer to a possibly-encoded block of memory, and an ImageDescription describing the format of that data. This is a really nice design, because it speaks to the likelihood that the data coming off the camera may already be compressed (always the case with DV, and often the case with other cameras — why burn bus bandwidth on uncompressed RGB data?) If you’re just saving the captured data to disk, it makes sense to just leave it compressed, but in this case, you’d want to decompress to a block of memory to run the barcode-search logic. It’s not easy code to write, but it’s very flexible and powerful. Three knocks against QTJ, though: there’s no onscreen Java component to render the capture data (although if you’re already decompressing to RGB, it’s a simple blit to get it into an AWT component), few Windows cameras include the needed QuickTime VDIG component (though you could presumably volume-license Abstract Plane’s software VDIG to deal with this), and of course QTJ doesn’t exist at all for Linux or other platforms.
I’m going to have to conclude at this point that there is no good cross-platform way to write this application today (although if you can think of something I’ve overlooked… sdljava maybe?… please post a comment). It’s a shame because the idea of using web-connected PC’s as barcode readers has myriad useful applications. Maybe the fact that Java, in all its bulk, can’t do it is a failure, but it’s also an opportunity, since Flash can’t do it either. See the “Rebooting Java Media” series for where I think things should go from here. And don’t expect Flash to sit still for long.
Booster Packs
What I set out to do in this blog was to propose a plausible, innovative application, not just a port of existing apps (”hey, let’s write iTunes in Java!”), and assess the abilities of Flash and the various Java media libraries to implement it as either an applet/presentation or a web app. There are surely lots of other valid business needs for media that have yet to be addressed by cross-platform executable environments like Flash and Java.
Again, a key to my thinking on this issue is trying to understand what application developers are thinking and why they do or don’t choose Java. Part of the reason this is important to me is that, as a Mac user, I keep seeing media devices come out that need a small amount of software support, and this software is invariably written as Windows executables. Like the “Lightning McQueen” digital cameras we got our kids for Christmas. Or the Sony Reader. The real functionality, and the value, is in the device, and surely the device makers aren’t wedded to Windows. And so I wish I could go to the relevant product managers and ask two questions:
- Did you consider Java for your software needs and find it lacking, or
- Did you never consider Java at all?
Honestly, the first answer would more reassuring, because something can be done about that. If Sony or Disney’s answer was “sure, we know Java’s cross-platform, but there’s no USB support, so how’s it going to work with devices?”, then at least there would be an obvious course of action to take. Things are worse if the answer were like “Java, isn’t that just for servers”, or “we’ve had bad experiences with Java in the past”, or the classic “no, it’s too slow”, then we have a much more serious problem. If Java has too little credibility after 10 years to even be considered for cross-platform development, then it’s done for, plain and simple.
I have a lurking suspicion in my dark, dark heart, that Sun has more people working on NetBeans than all other desktop Java technologies combined. If I knew that were the case, that this one IDE was the endgame of Desktop Java, I’d be pretty upset. And I’d probably be done with Desktop Java.


Hi Chris. Cool idea! I started building something recently with the free Flex SDK that could be used as a basis for this. I wanted to control a web-app by putting colored dots on my fingers and then have the webcam record my fingers and figure out my finger gestures. I got about halfway done before my flight reached it's destination. Here is some basic Flex code to get you started:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">
<mx:Script>
<![CDATA[
[Bindable] public var cam:Camera;
private function initApp():void
{
cam = Camera.getCamera();
cam.setMode(160,120,30);
v.attachCamera(cam);
}
private function pause():void
{
var bd:BitmapData = new BitmapData(160, 120);
bd.draw(v); // copies the webcam's pixels to a BitmapData object
// do something with the BitmapData now
}
]]>
</mx:Script>
<mx:VideoDisplay id="v" width="160" height="120"/>
<mx:Button label="Take Picture" click="pause()"/>
</mx:Application>
With the BitmapData object you can get the pixels in a variety of different ways. Check out the API documentation for BitmapData:
http://livedocs.macromedia.com/flex/201/langref/flash/display/BitmapData.html
I'd be interested in helping you figure out the algorithm to find the bar code and decipher it. Please email me if you want to work on this together.
-James Ward
james@jamesward.org
As an Ex-Flash Developer (currently working as Java Developer) i would probably prefer Flash over Java.
One of the major advantages Flash has, is the ability to create awesome User Interfaces. The Media Support, as you pointed out, lacks on both platforms but Adobe was always a step ahead i guess :-/
Chris, I've been following your java media work for a while, and it is very poignant. Java was positioned as applets, "life for web pages", and in fact flash does that to the level of hosting interesting games for kids.
desktop wise, the only mainstream java app I've seen, other than Java IDEs for server-side code, has to be azureus. And its big.
In a past life, I did work on software that got bundled with add on hardware for PCS. C++ and COM only. No .NET because it wasnt universal, so you couldn't rely on it being there. If you redistributed it you'd field all the support calls when it didnt work. So we stuck to C++, applying java dev practises: unit testing, cruise control, to the process. It mostly worked. We did check our com interfaces worked with .NET though, for the future.
the product still ships, and now there is a linux runtime. Behind the COM API were C++ classes, and they were STL+unicode across the board. It leaves the team with a cross compile, test and support problems, but its the best way to integrate with the OS.
And Java? I've never got drag and drop to work reliably on any of the linux desktops, even though its coming up to 25 years since the Mac launched.
Chris, I think you are right about NetBeans.... After all, they hired two brilliant Java developers with the potential to change the whole Java environment (JRuby dudes), and they put them on the netBeans team. huh?
But, the idea strikes me as a great one. how come no one has done this yet - using a camera as a barcode reader?
is that after a point, I expect the reader to take on faith my claim that Web 2.0's read/write nature will eventually express itself in media, and that we'll need media frameworks that offer more than just playback. So, I'd like to propose an application and go about seeing how feasible it is.
Take it on faith? Odeo and YouTube both offer "record your *cast directly from your browser" functionality now. I don't think you need to take it on faith when you see people doing it with Flash now. :P
As to your app, I don't know if it matters that Flash can't get at the pixels on the client. You can, and maybe *should* do that on the server -- at least for your CCG app. You would want a record of the full pixels on the server to add a level of auditability. Of course, if every card had a UUID, presumably it is already in a database somewhere. You would want some kind of "active agree" before a card could be "traded" in the database -- so someone couldn't shank your cards-- and in terms of initial registration, you would do better simply scanning a UUID on the "pack" that was purchased.
In terms of the bar code idea, though. It would be impressive to see things like AllConsuming or even Amazon Reviews supporting this.
Chris, I think you are right about NetBeans.... After all, they hired two brilliant Java developers with the potential to change the whole Java environment (JRuby dudes), and they put them on the netBeans team. huh?
Well, I guess it depends on priorities. Ruby isn't sweeping the world as a desktop development language either. Chris and I chatted about this on AIM a while back, and I would say his estimation here is probably right. However, I am not 100% that is necessarily a bad thing. One of the longstanding problems with the Java APIs was their mediocre support for tooling. Matisse is a pretty good example of where things can go when you work on both at the same time. All that said, media is just one part of the problem with desktop Java. Lack of any kind of modern HTML/Web support is a huge one up and down the line. Poor (if getting better) abilities to support modern desktop app metaphors is another. Poor base widget sets and the difficulty of things like Drag and Drop support stand out as other problems. The whole NetBeans RCP starts to address some problems, but the real lacking that Java has lies below the RCP level. I think if the focus on NetBeans has any real drawbacks, it is the denial that a lot of Sun technologies would see wider developer acceptance if they were not marketed as NetBeans-coupled, even when they aren't.
Hi Chris. Cool idea! I started building something recently with the free Flex SDK that could be used as a basis for this. I wanted to control a web-app by putting colored dots on my fingers and then have the webcam record my fingers and figure out my finger gestures. I got about halfway done before my flight reached it's destination. Here is some basic Flex code to get you started:James, that's awesome. Thanks for the unblocker. The ability to draw into the offscreen buffer is the missing link. I guess the next step for you from here would be to look at the pixels... might be simpler (if more expensive) to convert to HSV and see whether you can find a sufficient percentage of sufficiently green or red or whatever pixels (hue between specific values, with brightness and saturation over certain threshholds). This kind of reminds me of Lisa Lippincott's "Scroll Plate" from MacHack, when she held up styrofoam plates with colored arrows to her iSight to scroll the front-most window. Anyways, your hack is definitely doable, and figuring out bar-code scanning is just a more complex application of the same ideas. I have no damn time, but I've downloaded Flex in hopes of trying to dig into this. Thanks again.
Actually, you *can* get at pixel data from Flash using the BitmapData class - you can draw a Video object framegrab to the BitmapData object using BitmapData object's draw() method. It can also be done in Java (I actually wrote the code originally in Java and ported to Flash in an evening), although Flash is much nicer from a cross-platform compatibility (and this is from a true-blue Java guy).
I don't know if you're interested, but I actually just released a demo of a Flash-based barcode reader. See the details at:
http://www.brendonwilson.com/blog/2007/01/22/barcode-recognition-in-flash/
The code is still in its early form, but it provides a workable demonstration of what is possible. I hope to expand this code in the coming month or so to work with fixed focus webcams, such as those on the MacBook Pro, as many laptops are now shipping with webcams as standard integrated peripherals.
I'd really be interested in hearing what things people would like to build with this.
Actually, you *can* get at pixel data from Flash using the BitmapData class - you can draw a Video object framegrab to the BitmapData object using BitmapData object's draw() method.
That's exactly what the code I posted does. :)
Have you posted the ActionScript code you used to read the bar code from the BitmapData?
Thanks.
-James
Not yet - currently still a work in progress, as I'm trying to work through the problem of dealing with fixed focus lenses. I'm still trying to decide what to do with the library once it's done. I could release it as open source, or I could use it to develop a service built on top of it.
do u no how to unblock this page at a school computer if not a unblocking web search page thanks.
you have the right idea but think more about a sort of board like in yu-gi-oh! they use the dual disc's think something like that but usb with mic and not a bar code but more of a small chip in the bottom right corner of the cards that way your not have to scan it but just place it down on the board the board also that way depending on what TCG you play you can put your cards into defence mode or like MTG you have to tap your cards all the time and you can with a board hooked up to the computer by usb. yeah selling the packs and booster packs with the chip well bring money in but people would in joy a more of actual interaction because you need to still use your head when placing the right cards on that board.