Ejemplo n.º 1
0
def request_handler(request):
    if request["method"] == "GET":
        try:
            folder = request["values"]["type"]
            num = request["values"]["num"]
        except:
            return "Invalid Request: Must have args type and num"

        folder_path = "__HOME__/final_project/process_image/test_images/{}/".format(
            folders[folder])
        all_photos_in_folder = os.listdir(folder_path)

        if num != "0":
            for photo in all_photos_in_folder:
                if "barcode{}".format(num) in photo:
                    photo_path = folder_path + photo
                    break

            img = bcr.get_image(photo_path)
            if folder == 'product':
                img = bcr.isolate_barcode(img)
            return bcr.get_UPC(img)
        else:
            barcodes = []
            for photo in all_photos_in_folder:
                photo_path = folder_path + photo
                img = bcr.get_image(photo_path)
                if folder == 'product':
                    img = bcr.isolate_barcode(img)
                barcodes.append("".join(list(map(str, bcr.get_UPC(img)))))
            return barcodes
Ejemplo n.º 2
0
def process_image64(img_64):
	img_arr = np.frombuffer(base64.b64decode(img_64),np.uint8)
	img = cv2.imdecode(img_arr,cv2.IMREAD_COLOR)
	if Find_Barcode.thing(img,"X"):
		barcode = bcr.isolate_barcode(img) #img needs to be RGB
		UPC = bcr.get_UPC(img)
		if len(UPC) == 12 and -1 not in UPC:
			return UPC

	return google_image.get_label(img_64)
Ejemplo n.º 3
0
def process_image(img_path):
	img = bcr.get_image(img_path)
	if Find_Barcode.thing(img,"X"):
		try:
			barcode = bcr.isolate_barcode(img) #img needs to be RGB
			UPC = bcr.get_UPC(barcode)
			if len(UPC) == 12 and -1 not in UPC:
				UPC_text = "".join(list(map(str,UPC)))
				name = prod_info.getProductName(UPC_text)
				name = name.replace("'","")
				return name + ";" + UPC_text
		except:
			print("Couldn't find UPC")
	return google_image.get_label(img_path)
Ejemplo n.º 4
0
 def test_barcode5(self):
     img = bcr.get_image('test_images/product_barcodes/barcode5.JPG')
     img = bcr.isolate_barcode(img)
     self.assertEqual(bcr.get_UPC(img),
                      [0, 4, 3, 6, 1, 9, 5, 4, 0, 1, 2, 3])
Ejemplo n.º 5
0
 def test_barcode3(self):
     img = bcr.get_image('test_images/product_barcodes/barcode3.JPG')
     img = bcr.isolate_barcode(img)
     self.assertEqual(bcr.get_UPC(img),
                      [0, 4, 6, 5, 0, 0, 0, 2, 2, 5, 1, 7])
Ejemplo n.º 6
0
 def test_barcode4(self):
     img = bcr.get_image('test_images/product_barcodes/barcode4.JPG')
     img = bcr.isolate_barcode(img)
     self.assertEqual(bcr.get_UPC(img),
                      [0, 7, 8, 0, 0, 0, 0, 1, 2, 1, 9, 4])
Ejemplo n.º 7
0
 def test_barcode2(self):
     img = bcr.get_image('test_images/product_barcodes/barcode2.JPG')
     img = bcr.isolate_barcode(img)
     self.assertEqual(bcr.get_UPC(img),
                      [0, 1, 6, 0, 0, 0, 1, 2, 1, 8, 3, 6])
Ejemplo n.º 8
0
 def test_barcode1(self):
     img = bcr.get_image('test_images/plain_barcodes/barcode1.jfif')
     self.assertEqual(bcr.get_UPC(img),
                      [1, 2, 9, 0, 0, 2, 7, 0, 2, 0, 4, 7])
Ejemplo n.º 9
0
 def test_barcode1(self):
     img = bcr.get_image('test_images/product_barcodes/barcode1.JPG')
     img = bcr.isolate_barcode(img)
     self.assertEqual(bcr.get_UPC(img),
                      [3, 8, 1, 3, 7, 0, 0, 1, 5, 3, 1, 4])
Ejemplo n.º 10
0
 def test_barcode5(self):
     img = bcr.get_image('test_images/rotated_barcodes/barcode5.png')
     self.assertEqual(bcr.get_UPC(img),
                      [0, 3, 6, 0, 0, 0, 2, 9, 1, 4, 5, 2])
Ejemplo n.º 11
0
 def test_barcode4(self):
     img = bcr.get_image('test_images/rotated_barcodes/barcode4.jpeg')
     self.assertEqual(bcr.get_UPC(img),
                      [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2])
Ejemplo n.º 12
0
 def test_barcode3(self):
     img = bcr.get_image('test_images/rotated_barcodes/barcode3.jpg')
     self.assertEqual(bcr.get_UPC(img),
                      [6, 7, 1, 8, 6, 0, 0, 1, 2, 3, 2, 0])
Ejemplo n.º 13
0
 def test_barcode2(self):
     img = bcr.get_image('test_images/rotated_barcodes/barcode2.jpg')
     self.assertEqual(bcr.get_UPC(img),
                      [7, 2, 5, 2, 7, 2, 7, 3, 0, 7, 0, 6])