#python产品#barcode_recognition /将结果保存到Excel文件

时间:2018-08-09 12:52:08

标签: python opencv barcode image-recognition

我对我的“小”项目条形码识别感到困惑。我是python和所有编程人员中的新手。 所以我从互联网上借了一半代码,现在我正在尝试使其适应我的需求。 基本上应该做什么:

  1. 浏览文件夹中的所有图像以获取条形码编号。
  2. 将图像名称和条形码编号保存到Excel文件中。

听起来很简单,但对我而言却不行。.我现在停留了大约一周的时间,一直在寻找各种教程和本站点的内容,直到我决定在这里注册以提出这一解决方案或一些指导,我才在这里做错了。所以这是代码,也是我将结果添加到列表时的期望。 (无,无,无..) 附言我正在使用python 3.6,windows 7(有时是10,请不要问为什么..)

from __future__ import print_function
from os import listdir
from os.path import isfile, join
import pandas as pd
import pyzbar.pyzbar as pyzbar
import numpy as np
import cv2
import glob
import os
import xlwt
from tempfile import TemporaryFile

folder = "C:\\Users\\dava8001\\AppData\\Local\\Programs\\Python\\Python36-        32\\bar-code-project\\2018-08-07_Eurovaitine,Salma\\"
barcode = []

def decode(im) : 
  # Find barcodes and QR codes
  decodedObjects = pyzbar.decode(im)

  # Print results
  for obj in decodedObjects:

    onlyfiles = [f for f in listdir(folder) if isfile(join(folder, f))]
    print('Type : ', obj.type)
    code = print('Number : ', obj.data,'\n')
    barcode.append(code)

  return decodedObjects

# Display barcode and QR code location  
def display(im, decodedObjects):

  # Loop over all decoded objects
  for decodedObject in decodedObjects: 
    points = decodedObject.polygon

    # If the points do not form a quad, find convex hull
    if len(points) > 4 : 
      hull = cv2.convexHull(np.array([point for point in points],         dtype=np.float32))
      hull = list(map(tuple, np.squeeze(hull)))
    else : 
      hull = points;

    # Number of points in the convex hull
    n = len(hull)

    # Draw the convext hull
    for j in range(0,n):
      cv2.line(im, hull[j], hull[ (j+1) % n], (255,0,0), 3)

  # Display results 
  #cv2.imshow("Results", im);
  #cv2.waitKey(0);


# Main 
if __name__ == '__main__':

  # Read image
  #im = [i for i in glob.glob(folder + "*.jpg") if isfile(join(folder, i))]
  for img in glob.glob(folder + "*.jpg"):
      im = cv2.imread(img)

      decodedObjects = decode(im)
      display(im, decodedObjects)

#print(barcode)

我的出事就是这样。

  

类型:EAN13       编号:b'9000100960342'

     

类型:EAN13       编号:b'9000100961172'

     

类型:EAN13       编号:b'5060283070508'

     

类型:EAN13       编号:b'5201279037109'

     

类型:EAN13       编号:b'5201279037109'

     

类型:CODE128       编号:b'1000002125861'

     

类型:EAN13       号码:b'3574660244182'

     

类型:EAN13       编号:b'4026600682800'

     

类型:EAN13       编号:b'3282770104783'

     

类型:EAN13       编号:b'7070866024680'

     

类型:EAN13       编号:b'7070866024680'

     

类型:EAN13       编号:b'5903104370008'

     

类型:EAN13       编号:b'5902114231880'

     

类型:EAN13       编号:b'2355106901552'

     

类型:EAN13       编号:b'4770511211030'

     

类型:EAN13       编号:b'4770577797066'

     

类型:EAN13       编号:b'4170511791066'

     

类型:EAN13       编号:b'4770511191066'

     

类型:EAN13       编号:b'4170511197066'

     

类型:EAN13       编号:b'5060195750451'

     

类型:EAN13       编号:b'4771138392669'

     

类型:EAN13       编号:b'4771138392669'

 ###print(barcode)###
 >>> [None, None, None, None, None, None, None, None, None, None, None, None,        None, None, None, None, None, None, None, None, None, None]

想念你!

0 个答案:

没有答案