8 ms·
Detecting Barcodes in Images with Python and OpenCV
- thebenedict 12y agoI understand it's meant as a joke, but starting with "Stampedes of middle-aged midwestern women, their toothless gums bloodthirsty for 75% off the latest season of Game of Thrones at the local Wal-Mart." Could turn off a lot of people (women, older people, Wal-Mart shoppers, etc.) from what is otherwise a fun and well written technical post. I'd like to see HN being more inclusive. That said, enjoyed and upvoted the article.
- dontbeso 12y agopeople who are turned off by an obvious joke like that don't deserve to read this article. it was very informative and well-written.
- rtpg 12y agoContrary to how some people react to the "PC police", it is possible to be funny without being super hurtful to entire categories of people for little gain. There are levels of humour, but I agree with GP that the quoted quip is pretty rude (the toothless gum bit) , and it isn't even that funny!
- yuvadam 12y agoFunny how the joke is always at the expense of others (handicapped, disabled, oppressed, weak) and never self-humor, innit?
- GFK_of_xmaspast 12y agoThe amount of good technical articles out there that I haven't gotten around to reading yet is endless, no point in reading one written by an ass.
- zionsrogue 12y agoAuthor of the post here. Sorry to offend you. Certainly wasn't trying to be an ass. But when you write tons and tons of programming tutorials, sometimes it's fun to introduce a little humor, otherwise it becomes extremely dull. If anything, the introduction simply pointed out the consumerism flaws related to Black Friday. I didn't mean to single out a group of people.
- CJefferson 12y agoI find a good guide is to rewrite insults to aim at you, and your expected readers. If you don't want to do that, you probably shouldn't have put them in.
- zionsrogue 12y agoSomething to keep in mind for the next time.
- stronglikedan 12y agoFor what it's worth, I found the quip to be funny. I also found it to be appropriate in the context, as anyone who has braved the Black Friday crowd would (only once - lesson learned). But then again, I'm also one of those old curmudgeons who think that everybody gets their panties in a twist way to easily these days.
- kjs3 12y agoTranslation: I've spent my life freely and casually belittling people I see as beneath me, and am annoyed that these uppity women and minorities are feeling empowered enough to call me out on it. They should all mind their place. Being a privileged white male isn't what it used to be.
- stronglikedan 12y agoWhy would you think anyone else is beneath you? I'm sorry that you feel privileged in some way because you are white, but everyone is created equal, regardless of race. You'll be a happier person if you live and let live, instead of letting people annoy you so easily.
- company 12y agoJust another example of elitism prevalent among the tech community.
- ineedtosleep 12y agoIn all honesty, this comment and its children should just be deleted. It has degenerated this entire submission and, whether or not it was intentional, ruined any sort of discussion about the crux of the matter. If you're a bloodthirsty, toothless, middle-age woman -- sorry this submission was not meant for you. Carry on, and read another one of the millions of posts on the internet.
- rtpg 12y agoThis entire blog has loads of really interesting material on image manipulation with python. This blog was pretty interesting, it would have been cool to go the whole 9 yards and read the barcode though (maybe this technique isn't precise enough?)
- zionsrogue 12y agoHey, author of the post here. Detecting the barcode is actually the easy part. Reading the barcode is substantially harder. And there are many different types of barcode variations. It's not a simple problem, unfortunately. However, this approach could be used to read the barcode. I'll add a post related to reading the barcode to queue though! Thanks for the great feedback.
- mark-r 12y agoIf you restrict yourself to UPC barcodes it's actually quite easy. I've done it in pure Python, don't even need Numpy. Unfortunately it's not ready for prime time yet.
- wiredfool 12y agoI did a python barcode decoder for Code39 a few years ago: http://www.wiredfool.com/2006/07/04/barcode-recognition/ http://www.wiredfool.com/2006/07/04/barcode-recognition/ . Alternate symbologies aren't that hard to do since the decoding instructions are floating about. And helpfully enough, my code needed a pretty good crop on the barcode, and that's what this article gives you.
- zionsrogue 12y agoThis is great, thanks for sharing.
- mctx 12y agoDoes this technique only work if the barcode is either horizontal or vertical?
- zionsrogue 12y agoIt only works for horizontal barcodes. It's certainly possible to extend this code to work for vertical ones as well. A Radon transform might be a good start. And if you want something more powerful there is Haar cascades or HOG descriptors + Linear SVM.
- michaelt 12y agoI'd be interested to hear how it does on these: http://www.mjt.me.uk/posts/barcode-reader-test-cases/ http://www.mjt.me.uk/posts/barcode-reader-test-cases/
- clapas 12y agoApart from the fact of being an interesting article on CV, how would you avoid waiting to checkout to find out the price difference by scanning the barcode?
- DZittersteyn 12y agoIs there a reason to be doing doing a closing, and then a sequence of erosions, followed by dilations? Since closing(image, str.elem.) == erode(dilate(image, str.elem), str.elem), it feels like you could better use an erosion (remove noise) followed by a closing (to fill up the empty spaces) instead of the other way around?
- zionsrogue 12y agoGreat observation. But if you erode too early you run the risk of not being able to perform a closing and fill in the gaps between the vertical stripes of the barcode.
- DZittersteyn 12y agoYou could ofc. erode with a smaller element, and open with a larger one, but that might be just as parameter-tweaky as this approach ;)
- tim333 12y agoFunnily enough I was mucking about last night trying to get some bar code detection stuff going with python and it seemed everyone uses ZBar for that. Would that have done the job in this case? I guess the article is more of a teaching project than an attempt to read barcodes... ( https://pypi.python.org/pypi/zbar https://pypi.python.org/pypi/zbar )
- zionsrogue 12y agoI have heard of ZBar but have never used it. It looks like the Python package wraps a binary, correct? Anyway, it looks like it could do the job.
- tim333 12y agoYeah, it's basically written in C. Supposed to work quite well though I was having tech issues getting it up on the macbook.
- lftl 12y agoYep, I've used Zbar for barcode detection in photographs before. It wasn't particularly fast for my usage, but a lot of the photos I was scanning weren't particularly well cropped around the bar code. I'd be interested in seeing some benchmarks between this approach and Zbar. Also, a ton of the barcode scanning mobile apps use zbar as well (they all use zbar's default interface unchanged).
- zk00006 12y agoFunny how the article injects names of movies to the page to get higher page rank at Google. At least this was the strategy long time ago :)
- zionsrogue 12y agoActually, the only reason I mentioned movies/TV shows was because I had just watched the Black Friday episodes of South Park and used those as inspiration for the introduction.
- williamstein 12y agoSageMathCloud worksheet illustrating using Python with OpenCV (with a picture of my halfpipe): http://tinyurl.com/lnyv7qd http://tinyurl.com/lnyv7qd
- hackerews 12y agoNice! Works really well. Set up an API for the script so you can try it out without coding it up: https://api.blockspring.com/pkpp1233/d80c0541e3b744bb7695be291d08543e https://api.blockspring.com/pkpp1233/d80c0541e3b744bb7695be2...
- zionsrogue 12y agoHey, that's very cool! Thanks for putting the API together :-)
- hackerews 12y agoNo problem haha. Took about 30 seconds with the code being there. Thanks for the awesome tutorial.
- deleted 12y ago[deleted]