import pyzbar.pyzbar as pyzbar
#import pyzbar

def decode(im) : 
  # Find barcodes and QR codes
  decodedObjects = pyzbar.decode(im)
  # Print results
  Liste=[]
  for obj in decodedObjects:
  #print('Type : ', obj.type)
  #print('Data : ', obj.data,'\n')
  	Liste.append([obj.type, obj.data])
  
  return Liste


def emotion(Liste):

	if(len(Liste)>1): #Si trop d'élément à traiter
	    print("confus")

	if(len(Liste)==1): #Si le bon nombre d'élément
	    
	    print(Liste[0][1])
	    m=Liste[0][1].decode('utf-8')

	    

# 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);


