Advertisement
Guest User

QRbar-cv.py

a guest
Jan 3rd, 2013
4,476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3. # Author : Jimmyromanticdevil
  4. # QRbar-cv
  5. #
  6. # Proc of consept :
  7. # this is just simple code from part of my work for QRcode & Barcode scanner with webcame stuff
  8. # i am using Opencv for realtime track the image & zbar for decode the image
  9. #
  10. # Dependency :
  11. #
  12. #
  13. # Some of Good Refrensi stuff :
  14. #   https://github.com/jayrambhia/Install-OpenCV
  15. #   http://nwlinux.com/install-qtqr-in-ubuntu-10-04-lucid-using-apt-get/
  16. #   http://zbar.sourceforge.net/
  17.  
  18.  
  19. import cv2.cv as cv #Use OpenCV-2.4.3
  20. import zbar
  21.  
  22. def scanner_procces(frame,set_zbar):    
  23.     set_width = 100.0 / 100
  24.     set_height = 90.0 / 100
  25.    
  26.     coord_x = int(frame.width * (1 - set_width)/2)
  27.     coord_y = int(frame.height * (1 - set_height)/2)
  28.     width = int(frame.width * set_width)
  29.     height = int(frame.height * set_height)
  30.    
  31.     get_sub = cv.GetSubRect(frame, (coord_x+1, coord_y+1, width-1, height-1))
  32.    
  33.     cv.Rectangle(frame, (coord_x, coord_y), (coord_x + width, coord_y + height), (255,0,0))
  34.    
  35.     cm_im = cv.CreateImage((get_sub.width, get_sub.height), cv.IPL_DEPTH_8U, 1)
  36.     cv.ConvertImage(get_sub, cm_im)
  37.     image = zbar.Image(cm_im.width, cm_im.height, 'Y800', cm_im.tostring())
  38.    
  39.     set_zbar.scan(image)
  40.     for symbol in image:
  41.             print '\033[1;32mResult : %s symbol "%s" \033[1;m' % (symbol.type,symbol.data)
  42.            
  43.     cv.ShowImage("webcame", frame)
  44.     #cv.ShowImage("webcame2", get_sub)
  45.     cv.WaitKey(10)
  46.  
  47.    
  48. if __name__ == "__main__":
  49.     #set up our stuff
  50.     cv.NamedWindow("webcame", cv.CV_WINDOW_AUTOSIZE)
  51.     capture = cv.CaptureFromCAM(-1)
  52.     set_zbar = zbar.ImageScanner()
  53.     while True:
  54.           frame = cv.QueryFrame(capture)
  55.           scanner_procces(frame,set_zbar)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement