def scanner_procces(self, frame, set_zbar): codigo = 0 set_width = 100.0 / 100 set_height = 90.0 / 100 coord_x = int(frame.width * (1 - set_width) / 2) coord_y = int(frame.height * (1 - set_height) / 2) width = int(frame.width * set_width) height = int(frame.height * set_height) get_sub = cv.GetSubRect( frame, (coord_x + 1, coord_y + 1, width - 1, height - 1)) cv.Rectangle(frame, (coord_x, coord_y), (coord_x + width, coord_y + height), (255, 0, 0)) cm_im = cv.CreateImage((get_sub.width, get_sub.height), cv.IPL_DEPTH_8U, 1) cv.ConvertImage(get_sub, cm_im) image = zbar.Image(cm_im.width, cm_im.height, 'Y800', cm_im.tostring()) set_zbar.scan(image) for symbol in image: print '\033[1;32mResult : %s symbol "%s" \033[1;m' % (symbol.type, symbol.data) global codigo codigo = symbol.data cv.ShowImage("webcame", frame) #cv.ShowImage("webcame2", get_sub) cv.WaitKey(500) return codigo
def placeImages(self, imageList): imageListLength = min(len(imageList), self._maxImages) self._currentNumCameras = imageListLength for i in range(imageListLength): image = imageList[i] if(i == self._selectedCameraId): cv.Resize(image, self._bigRegion) smallRegion = self._smallImageAreaList[i] cv.Resize(image, smallRegion) cv.ConvertImage(self._mixMat, self._convertedMat, cv.CV_CVTIMG_SWAP_RB) return self._convertedMat
def scanner_procces(frame, set_zbar): global x right = 'correct' fail = 'fail' set_width = 100.0 / 100.0 set_height = 100.0 / 100.0 global count coord_x = int(frame.width * (1 - set_width) / 2) coord_y = int(frame.height * (1 - set_height) / 2) width = int(frame.width * set_width) height = int(frame.height * set_height) get_sub = cv.GetSubRect(frame, (coord_x + 1, coord_y + 1, width - 1, height - 1)) cv.Rectangle(frame, (coord_x, coord_y), (coord_x + width, coord_y + height), (255, 0, 0)) cm_im = cv.CreateImage((get_sub.width, get_sub.height), cv.IPL_DEPTH_8U, 1) cv.ConvertImage(get_sub, cm_im) image = zbar.Image(cm_im.width, cm_im.height, 'Y800', cm_im.tostring()) set_zbar.scan(image) for symbol in image: print '\033[1;32mResult : %s symbol "%s" \033[1;m' % (symbol.type, symbol.data) data = symbol.data if x != data and len(data) > 0: x = data if x == "a_medicine": pwm.write(0.5) print x else: pwm.write(0.9) print x cv.ShowImage("webcame", frame) #cv.ShowImage("webcame2", get_sub) cv.WaitKey(10)
def getImage(self, outOfMemory): self._outOfMemory = outOfMemory cv.ConvertImage(self._currentImage, self._convertedMat, cv.CV_CVTIMG_SWAP_RB) return self._convertedMat
def ActivateCamera(): capture = cv.CaptureFromCAM(0) # decalre the zbar_setter as zbar scanner zbar_scanner = zbar.ImageScanner() checkScan = False; while (checkScan == False): # create the variable as a frame of camera img = cv.QueryFrame(capture) height = int(img.height) width = int(img.width) SubRect = cv.GetSubRect(img, (1, 1, width - 1, height - 1)) # cv.Rectangle(img,(0,0),(width,height),(255,0,0)) # to create the image set_image = cv.CreateImage((SubRect.width, SubRect.height), cv.IPL_DEPTH_8U, 1) cv.ConvertImage(SubRect, set_image) image = zbar.Image(set_image.width, set_image.height, 'Y800', set_image.tostring()) zbar_scanner.scan(image) for item in image: getFromScan = item.data splitString = getFromScan.split(":") checkProductName = splitString[0] priceOfdata = splitString[1] checkExpirydate = splitString[2] itemCode = splitString[3] data = {'price': splitString[1] , 'Code': splitString[3], 'name': splitString[0], 'expiryDate': splitString[2], 'Checkin': str(datetime.now())} checkDuplicate = False counterOuter = 0 """""" # 1.1 for i in itemlist: # 2.1 same product name if i['name'] == checkProductName: print "have same product name" checkDuplicate = True # 3.1 same expiryDate if i['expiryDate'] == checkExpirydate: print "have same expiryDate" print i['Code'] list_of_ItemCode = CreateArrayOfKeyDict(json.dumps(i['Code'])) list_of_Checkin = CreateArrayOfKeyDict(json.dumps(i['Checkin'])) counterInner = 0 for itemID in listOfCode: print 'U r in the new for loop' # 4.1 itemCode(itemID) is duplicate print 'itemID is ' + itemID print 'itemCode is ' + itemCode if itemID == itemCode: # 5.1 array of Code is equal 1 if len(listOfCode) == 1: # remove statement print 'U are in the code is duplicate condition' checkDuplicate = True removeItemKey = itemlist_key[counterOuter] print removeItemKey forRemoveDupCode = firebase.ref('CustomerInfo/-KqsdeuVyyatxKELuMs4/Item') forRemoveDupCode.child(removeItemKey).delete() # create new data checkoutData = data = {'price': splitString[1], 'Code': itemCode, 'name': checkProductName, 'expiryDate': checkExpirydate, 'Checkin': list_of_Checkin[counterInner], 'Checkout': str(datetime.now()), 'Province' : 'Chiang Mai'} # add to usage database usageItem = firebase.ref('Usage') usageItem.push(checkoutData) itemlist.pop(counterOuter) itemlist_key.pop(counterOuter) print ("Successful for removing item" + getFromScan) microgear.chat("outdoor/temp", json.dumps(itemlist)) time.sleep(5) return True # 5.2 array of Code is greater than 1 else: # delete item code from dict and update # update statement print 'Code duplicate but length is greater than 1 condition' checkDuplicate = True removeItemKey = itemlist_key[counterOuter] print removeItemKey # update item code list_of_ItemCode.remove(itemID) # getting new values to update data in firebase newCode5 = ReplaceValuesInDict(json.dumps(list_of_ItemCode)) # update values in firebase forRemoveExCode = firebase.ref('CustomerInfo/-KqsdeuVyyatxKELuMs4/Item') forRemoveExCode.child(removeItemKey).child('Code').set(newCode5) # update local database i['Code'] = UpdateNewValuesDictKey(list_of_ItemCode) # create new data checkoutData = data = {'price': splitString[1], 'Code': itemCode, 'name': checkProductName, 'expiryDate': checkExpirydate, 'Checkin': list_of_Checkin[counterInner], 'Checkout': str(datetime.now()), 'Province' : 'Chiang Mai'} # update check in list_of_Checkin.pop(counterInner) updateCheckinValues = ReplaceValuesInDict(json.dumps(list_of_Checkin)) forupdateNewCheckin = firebase.ref('CustomerInfo/-KqsdeuVyyatxKELuMs4/Item') forupdateNewCheckin.child(removeItemKey).child('Checkin').set(updateCheckinValues) i['Checkin'] = UpdateNewValuesDictKey(list_of_Checkin) # add to usage database usageItem = firebase.ref('Usage') usageItem.push(checkoutData) print ("Successful for removing item Code") microgear.chat("outdoor/temp", json.dumps(itemlist)) time.sleep(5) return True counterInner += 1 # 4.2 itemCode(itemID) is not duplicate else: # update statement with append new itemCode into existing dict print 'update' checkDuplicate = True removeItemKey = itemlist_key[counterOuter] # update item code # add new code to list list_of_ItemCode.append(itemCode) # getting new values to update data in firebase newCode5 = ReplaceValuesInDict(json.dumps(list_of_ItemCode)) # update values in firebase forupdateNewCode = firebase.ref('CustomerInfo/-KqsdeuVyyatxKELuMs4/Item') forupdateNewCode.child(removeItemKey).child('Code').set(newCode5) # update local database i['Code'] = UpdateNewValuesDictKey(list_of_ItemCode) # update check in # add new check in time to list list_of_Checkin.append(data['Checkin']) # getting new values to update data in firebase newCodeForCheckin = ReplaceValuesInDict(json.dumps(list_of_Checkin)) # update values in firebase forupdateNewCheckin = firebase.ref('CustomerInfo/-KqsdeuVyyatxKELuMs4/Item') forupdateNewCheckin.child(removeItemKey).child('Checkin').set(newCodeForCheckin) # update local database i['Checkin'] = UpdateNewValuesDictKey(list_of_Checkin) microgear.chat("outdoor/temp", json.dumps(itemlist)) time.sleep(5) return True # 3.2 expiry date is not duplicate else: # add statement foraddnewDate = firebase.ref('CustomerInfo/-KqsdeuVyyatxKELuMs4/Item') NewItemKey = foraddnewDate.push(data) print("Successful for adding new date") abcd = json.dumps(NewItemKey.values()) pkpk = re.sub('[^a-zA-Z_0-9-]+', '', abcd) itemlist.append(data) itemlist_key.append(pkpk) microgear.chat("outdoor/temp", json.dumps(itemlist)) time.sleep(5) return True counterOuter += 1 # 1.2 if checkDuplicate == false it will add the new one if checkDuplicate == False: # add statement print 'add new item' foraddNewitemRef = firebase.ref('CustomerInfo/-KqsdeuVyyatxKELuMs4/Item') NewItemKey = foraddNewitemRef.push(data) print("Successful for adding new item") abcd = json.dumps(NewItemKey.values()) pkpk = re.sub('[^a-zA-Z_0-9-]+', '', abcd) itemlist.append(data) itemlist_key.append(pkpk) microgear.chat("outdoor/temp", json.dumps(itemlist)) time.sleep(5) return True #cv.ShowImage("ISR Scanner", img) # less for fast video rendering cv.WaitKey(1)
def ActivateCamera(): capture = cv.CaptureFromCAM(0) # decalre the zbar_setter as zbar scanner zbar_scanner = zbar.ImageScanner() checkScan = False while (checkScan == False): # create the variable as a frame of camera img = cv.QueryFrame(capture) height = int(img.height) width = int(img.width) SubRect = cv.GetSubRect(img, (1, 1, width - 1, height - 1)) # cv.Rectangle(img,(0,0),(width,height),(255,0,0)) # to create the image set_image = cv.CreateImage((SubRect.width, SubRect.height), cv.IPL_DEPTH_8U, 1) cv.ConvertImage(SubRect, set_image) image = zbar.Image(set_image.width, set_image.height, 'Y800', set_image.tostring()) zbar_scanner.scan(image) for item in image: getFromScan = item.data splitString = getFromScan.split(":") checkProductName = splitString[0] checkExpirydate = splitString[2] itemCode = splitString[3] # data = {"name": getFromScan} data = { 'price': 30, 'Code': splitString[3], 'name': splitString[0], 'expiryDate': splitString[2] } checkDuplicate = False counterOuter = 0 """""" # 1.1 for i in itemlist: # 2.1 same product name if i['name'] == checkProductName: print "have same product name" checkDuplicate = True # 3.1 same expiryDate if i['expiryDate'] == checkExpirydate: print "have same expiryDate" """ print i['Code'] + ' is the old item code' i['Code'] += ',' + itemCode print i['Code'] + ' is the new item code' """ print i['Code'] CodeString = json.dumps(i['Code']) cleanCodeString = CodeString.replace('"', '') listOfCode = cleanCodeString.split(',') counterInner = 0 for itemID in listOfCode: print 'U r in the new for loop' # 4.1 itemCode(itemID) is duplicate print 'itemID is ' + itemID print 'itemCode is ' + itemCode if itemID == itemCode: # 5.1 array of Code is equal 1 if len(listOfCode) == 1: # remove statement print 'U are in the code is duplicate condition' checkDuplicate = True removeItemKey = itemlist_key[counterOuter] print removeItemKey forRemoveDupCode = firebase.ref( 'CustomerInfo/-KqsdeuVyyatxKELuMs4/Item' ) forRemoveDupCode.child( removeItemKey).delete() # ref.child(removeItemKey).delete() itemlist.pop(counterOuter) itemlist_key.pop(counterOuter) # """ # """ print("Successful for removing item" + getFromScan) microgear.chat("outdoor/temp", json.dumps(itemlist)) time.sleep(5) return True # 5.2 array of Code is greater than 1 else: # delete item code from dict and update # update statement print 'Code duplicate but length is greater than 1 condition' checkDuplicate = True removeItemKey = itemlist_key[counterOuter] print removeItemKey # for update duplicate product name and expirydate but itemCode(itemID) # i['Code'] += ',' + itemCode del listOfCode[counterInner] newCode = json.dumps(listOfCode) newCode1 = newCode.replace('"', '') newCode2 = newCode1.replace('/', '') newCode3 = newCode2.replace('[', '') newCode4 = newCode3.replace(']', '') newCode5 = newCode4.replace(' ', '') forRemoveExCode = firebase.ref( 'CustomerInfo/-KqsdeuVyyatxKELuMs4/Item' ) forRemoveExCode.child(removeItemKey).child( 'Code').set(newCode5) newListCode = '' for i in listOfCode: newListCode += i i['Code'] = newListCode """ # """ print("Successful for removing item Code") microgear.chat("outdoor/temp", json.dumps(itemlist)) time.sleep(5) return True counterInner += 1 # 4.2 itemCode(itemID) is not duplicate else: # update statement with append new itemCode into existing dict print 'update' checkDuplicate = True removeItemKey = itemlist_key[counterOuter] listOfCode.append(itemCode) newCode = json.dumps(listOfCode) newCode1 = newCode.replace('"', '') newCode2 = newCode1.replace('/', '') newCode3 = newCode2.replace('[', '') newCode4 = newCode3.replace(']', '') newCode5 = newCode4.replace(' ', '') forupdateNewCode = firebase.ref( 'CustomerInfo/-KqsdeuVyyatxKELuMs4/Item') forupdateNewCode.child(removeItemKey).child( 'Code').set(newCode5) newListCode = '' for i in listOfCode: newListCode += i i['Code'] = newListCode microgear.chat("outdoor/temp", json.dumps(itemlist)) time.sleep(5) return True # 3.2 expiry date is not duplicate else: # add statement checkDuplicate = True foraddnewDate = firebase.ref( 'CustomerInfo/-KqsdeuVyyatxKELuMs4/Item') NewItemKey = foraddnewDate.push(data) print("Successful for adding new date") abcd = json.dumps(NewItemKey.values()) pkpk = re.sub('[^a-zA-Z_0-9-]+', '', abcd) itemlist.append(data) itemlist_key.append(pkpk) microgear.chat("outdoor/temp", json.dumps(itemlist)) time.sleep(5) return True counterOuter += 1 # 1.2 if checkDuplicate == false it will add the new one if checkDuplicate == False: # add statement print 'add new item' foraddNewitemRef = firebase.ref( 'CustomerInfo/-KqsdeuVyyatxKELuMs4/Item') NewItemKey = foraddNewitemRef.push(data) print("Successful for adding new item") abcd = json.dumps(NewItemKey.values()) pkpk = re.sub('[^a-zA-Z_0-9-]+', '', abcd) itemlist.append(data) itemlist_key.append(pkpk) microgear.chat("outdoor/temp", json.dumps(itemlist)) """ print abcd print data print pkpk""" time.sleep(5) return True #cv.ShowImage("ISR Scanner", img) # less for fast video rendering cv.WaitKey(1)
def ActivateCamera(): capture = cv.CaptureFromCAM(0) # decalre the zbar_setter as zbar scanner zbar_scanner = zbar.ImageScanner() checkScan = False; while (checkScan == False): # create the variable as a frame of camera img = cv.QueryFrame(capture) height = int(img.height) width = int(img.width) SubRect = cv.GetSubRect(img, (1, 1, width - 1, height - 1)) # cv.Rectangle(img,(0,0),(width,height),(255,0,0)) # to create the image set_image = cv.CreateImage((SubRect.width, SubRect.height), cv.IPL_DEPTH_8U, 1) cv.ConvertImage(SubRect, set_image) image = zbar.Image(set_image.width, set_image.height, 'Y800', set_image.tostring()) zbar_scanner.scan(image) for item in image: getFromScan = item.data checkExisting = [getFromScan] data = {"name": getFromScan} checkDuplicate = False counter = 0 for i in itemlist: if checkExisting == i: checkDuplicate = True removeItemKey = itemlist_key[counter] print removeItemKey forremove = firebase.ref('CustomerInfo/-KqsdeuVyyatxKELuMs4/Item') forremove.child(removeItemKey).delete() itemlist.pop(counter) itemlist_key.pop(counter) print ("Successful for removing item" + getFromScan) time.sleep(3) return False counter += 1 if checkDuplicate == False: foraddNewitemRef = firebase.ref('CustomerInfo/-KqsdeuVyyatxKELuMs4/Item') NewItemKey = foraddNewitemRef.push(data) print("Successful for adding new item" ) abcd = json.dumps(NewItemKey.values()) pkpk = re.sub('[^a-zA-Z_0-9-]+', '', abcd) itemlist.append(checkExisting) itemlist_key.append(pkpk) time.sleep(3) return True cv.ShowImage("ISR Scanner", img) # less for fast video rendering cv.WaitKey(1)