コード例 #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
コード例 #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)
コード例 #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)
コード例 #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])
コード例 #5
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])
コード例 #6
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])
コード例 #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])
コード例 #8
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])