def processAllCroppedImages():
	for (dirpath, dirnames, filenames) in os.walk(croppedImageDirectory):
		for filename in filenames:
			if not filename.endswith(".png"):
				continue
			
			processImage.processImage(cv2.imread(os.path.join(dirpath, filename)), filename, orbIcons)
def processAllCroppedImages():
    for (dirpath, dirnames, filenames) in os.walk(croppedImageDirectory):
        for filename in filenames:
            if not filename.endswith(".png"):
                continue

            processImage.processImage(
                cv2.imread(os.path.join(dirpath, filename)), filename,
                orbIcons)
Exemple #3
0
def get_image_rdd(sc, n_groups=None, start=0, end=10, resize=0.1, val=0):
    '''
        Retrieve pixels as RDDs from images
        Also do reshape to n_groups of train data

        Update on 12/05/15: 
            return (index, feature) and (index, label)
            if n_groups != None, return reshaped features and labels
    '''

    import os
    import numpy as np
    from processImage import processImage

    if val == 1:
        images = ["im01453.jpg"]

        imgsRDD = sc.parallelize(images)
        pixelsRDD = imgsRDD.flatMap(
            lambda x: processImage(x, resizeTo=resize, val=1))

        RDDind = pixelsRDD.zipWithIndex()
        indRDD = RDDind.map(lambda (data, index): (index, data))
        index_feature = indRDD.map(lambda (index, data): (index, data[:-1]))
        index_label = indRDD.map(lambda (index, data): (index, data[-1]))

        return index_feature, index_label

    else:
        images = os.listdir("../Original/train/")

        imgsRDD = sc.parallelize(images[start:end])
        pixelsRDD = imgsRDD.flatMap(lambda x: processImage(x, resizeTo=resize))

        RDDind = pixelsRDD.zipWithIndex()
        indRDD = RDDind.map(lambda (data, index): (index, data))
        index_feature = indRDD.map(lambda (index, data): (index, data[:-1]))
        index_label = indRDD.map(lambda (index, data): (index, data[-1]))

        if n_groups == None:
            return index_feature, index_label

        # Do reshape
        # Do a following map to convert from resultiterable to list
        regroup_feature = index_feature.groupBy(lambda x: x[0] % n_groups).map(
            lambda (idx, x): (idx, sorted(x)))
        regroup_label = index_label.groupBy(lambda x: x[0] % n_groups).map(
            lambda (idx, x): (idx, sorted(x)))
        return regroup_feature, regroup_label
Exemple #4
0
def get_image_rdd(sc, n_groups=None, start=0, end=10, resize=0.1, val=0):
    '''
        Retrieve pixels as RDDs from images
        Also do reshape to n_groups of train data

        Update on 12/05/15: 
            return (index, feature) and (index, label)
            if n_groups != None, return reshaped features and labels
    '''

    import os
    import numpy as np
    from processImage import processImage

    if val == 1:
        images = ["im01453.jpg"]

        imgsRDD = sc.parallelize(images)
        pixelsRDD = imgsRDD.flatMap(lambda x : processImage(x, resizeTo=resize, val=1))

        RDDind = pixelsRDD.zipWithIndex()
        indRDD = RDDind.map(lambda (data,index):(index,data))
        index_feature = indRDD.map(lambda (index,data): (index,data[:-1]))
        index_label = indRDD.map(lambda (index,data): (index,data[-1]))

        return index_feature, index_label

    else:
        images = os.listdir("../Original/train/")

        imgsRDD = sc.parallelize(images[start:end])
        pixelsRDD = imgsRDD.flatMap(lambda x : processImage(x, resizeTo=resize))

        RDDind = pixelsRDD.zipWithIndex()
        indRDD = RDDind.map(lambda (data,index):(index,data))
        index_feature = indRDD.map(lambda (index,data): (index,data[:-1]))
        index_label = indRDD.map(lambda (index,data): (index,data[-1]))

        if n_groups == None:
            return index_feature, index_label
        
        # Do reshape
        # Do a following map to convert from resultiterable to list
        regroup_feature = index_feature.groupBy(lambda x: x[0] % n_groups).map(lambda (idx, x): (idx, sorted(x)))
        regroup_label = index_label.groupBy(lambda x: x[0] % n_groups).map(lambda (idx, x): (idx, sorted(x)))
        return regroup_feature, regroup_label
Exemple #5
0
def identifyfaces():
    pi = processImage.processImage('haarcascade_frontalface_default.xml')
    array = []
    link = request.json.get('link')
    response = pi.setFaces(link)
    im = imgApi.imgApi('b75fd7f114f5f5e',
                       '2be8f5d1754bcc269c6df45d2f447bcc8c8e5cf9')
    client = im.authImgur()
    img = im.uploadImg(response, client)
    return jsonify({'img': '%s' % img})
Exemple #6
0
def readStack(playerReg):
            # ===== read stack ===== #
            imgArr = playerReg.stack.img.copy()
            isSittingOut = False
            isAllIn = False
            isNoPlayer = False
            # check for no stack present - sum up colors greater than threshold
            threshold = 150
            totalCount  = imgArr.size
            threshCount = imgArr[imgArr>200].size
            proportion  = 100*threshCount/totalCount
            # number 1 has 27 pixels, stack image size is 87*17, which makes digit 1 ~1.8% of the image
            stackExists = proportion > 1
            if stackExists:
                # grab 1st digit and classify (numbers 1-9, A or S - 0 not an option for 1st digit)
                digitOne = processImage(imgArr,'stackCheck',returnBin=True)
                imageCat = classifyMultiImage(digitOne,'digit','digitTheta.csv')
                if imageCat == 'S':
                    isSittingOut = True
                    stack = 0
                elif imageCat == 'A':
                    isAllIn = True
                    stack = 0
                elif int(imageCat) > 0 and int(imageCat) <=9:
                    # classify each digit, add digits sequentially to get stack value
                    (digitBin,numDigits) = processImage(imgArr,'stack',returnBin=True)
                    digitArr = np.zeros(numDigits)
                    stack = 0
                    for i in range(numDigits):
			if numDigits == 1:
			    thisDigit   = classifyMultiImage(digitBin[:,:],'digit','digitTheta.csv')
			else:
			    thisDigit   = classifyMultiImage(digitBin[:,:,i],'digit','digitTheta.csv')
                        if thisDigit == 'A' or thisDigit == 'S':
                            raise ValueError('digit misread as A or S when reading stack')
                        stack = stack + int(thisDigit)*10**(numDigits-i-1)
                else:
                    raise ValueError('no valid integer read as first digit of stack')
            else:
                stack = 0
                isNoPlayer = True

            return stack,isSittingOut,isAllIn,isNoPlayer
def loadImage():
    global cv2_image
    file_path = tk.filedialog.askopenfilename()

    cv2_image = processImage.processImage(file_path)
    pil_image = Image.fromarray(cv2_image)

    tk_image = ImageTk.PhotoImage(pil_image)

    w.imagePreview.configure(image=tk_image)
    w.imagePreview.image = tk_image
    w.imagePath.configure(text=file_path)

    print('TestGUI_support.loadImage')
    sys.stdout.flush()
Exemple #8
0
def readFaceCard(imgArr):
    imgType = 'faceCard'
    (valBin,suitBin) = processImage(imgArr,imgType,returnBin=True)

    # ===== classify value ===== #
    imgType = 'cardVal'
    parameterName = 'cardValTheta.csv'
    val = classifyMultiImage(valBin,imgType,parameterName)

    # ===== classify suit ===== #
    imgType = 'suit'
    parameterName = 'suitTheta.csv'
    #print suitBin,suitBin.shape
    suit = classifyMultiImage(suitBin,imgType,parameterName)
    
    return val,suit
Exemple #9
0
def readBet(playerReg,p):
	chipSideList = ['left','left','left','right','right','right']
	chipSide = chipSideList[p]
	betImg = playerReg.bet.img
	(digitBin,numDigits) = processImage(betImg,'bet'+chipSide)
	if numDigits == 0:
	    return 0
	else:
	    bet = 0
        for i in range(numDigits):
	    if numDigits == 1:
		thisDigit   = classifyMultiImage(digitBin[:,:],'betDigit','betDigitTheta.csv')
	    else:
		thisDigit   = classifyMultiImage(digitBin[:,:,i],'betDigit','betDigitTheta.csv')
            bet = bet + int(thisDigit)*10**(numDigits-i-1)
	return bet
def cropNewImages(process = True):
	f = []
	
	# Make cropped image directory if necessary
	if not os.path.exists(croppedImageDirectory):
		os.makedirs(croppedImageDirectory)
	
	# Loop through new iamges
	for (dirpath, dirnames, filenames) in os.walk(screenshotsLocation):
		for filename in filenames:
			if not filename.endswith(".png"): # If it is unexpected, ignore it
				continue
			
			path = os.path.join(dirpath, filename)
			img = cv2.imread(path)						# Read image
			cropped = img[405:705, 18:374]				# Crop image
			if not process or processImage.processImage(cropped, filename, orbIcons):	# If processing image succeeds
				outputPath = os.path.join(croppedImageDirectory, filename)
				cv2.imwrite(outputPath, cropped)		# Save croppedImage
				os.remove(path)							# Only delete it if success (for now)
			else:
				print "Unable to process image", filename
Exemple #11
0
def checkHero(playerReg):
    	heroArr = np.array([[0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0],
		       	[0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0],
		    	[0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1],
		    	[0,1,1,1,1,0,0,1,1,0,0,1,1,0,0,0,1,1,1,1],
		    	[1,1,1,0,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,1],
		    	[1,1,0,0,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,1],
		    	[1,1,0,0,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,1],
		    	[1,1,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,1,0,1],
		    	[1,1,1,0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,0,1],
		    	[0,1,1,1,1,0,0,1,1,0,0,0,1,1,1,0,1,1,0,1]])
	nameImg = playerReg.name.img.copy()
        playerArr = processImage(nameImg,'heroName')
	if playerArr.shape == heroArr.shape:
		matchVal =  100*(playerArr==heroArr).sum()/playerArr.size
		negMatchVal = 100*((-1*playerArr+2)==heroArr).sum()/playerArr.size
	else:
		matchVal,negMatchVal = 0,0
	if matchVal >= 90 or negMatchVal >= 90:
		return True
	else:
		return False
Exemple #12
0
def readPot(tableReg):
    imgArr = tableReg.pot.img.copy()
    # check for pot
    threshold = 150
    totalCount  = imgArr.size
    threshCount = imgArr[imgArr>threshold].size
    proportion  = 100*threshCount/totalCount
    potExists = proportion > 1
    if potExists:
        # classify each digit, add digits sequentially to get stack value
        (digitBin,numDigits) = processImage(imgArr,'pot',returnBin=True)
        pot = 0
        for i in range(numDigits):
	    if numDigits == 1:
		thisDigit   = classifyMultiImage(digitBin[:,:],'digit','digitTheta.csv')
	    else:
		thisDigit   = classifyMultiImage(digitBin[:,:,i],'digit','digitTheta.csv')
            if thisDigit == 'A' or thisDigit == 'S':
                raise ValueError('digit misread as A or S when reading pot')
            pot = pot + int(thisDigit)*10**(numDigits-i-1)
    else:
        pot = 0
    return pot
def cropNewImages(process=True):
    f = []

    # Make cropped image directory if necessary
    if not os.path.exists(croppedImageDirectory):
        os.makedirs(croppedImageDirectory)

    # Loop through new iamges
    for (dirpath, dirnames, filenames) in os.walk(screenshotsLocation):
        for filename in filenames:
            if not filename.endswith(".png"):  # If it is unexpected, ignore it
                continue

            path = os.path.join(dirpath, filename)
            img = cv2.imread(path)  # Read image
            cropped = img[405:705, 18:374]  # Crop image
            if not process or processImage.processImage(
                    cropped, filename,
                    orbIcons):  # If processing image succeeds
                outputPath = os.path.join(croppedImageDirectory, filename)
                cv2.imwrite(outputPath, cropped)  # Save croppedImage
                os.remove(path)  # Only delete it if success (for now)
            else:
                print "Unable to process image", filename
Exemple #14
0
    setPoint = 35
    setSpeed = 30
    distr = dist - setPoint
    speedr = (dist - prevDist) / 0.3

    #ABS = 0.3313*distr + 3.3963*speedr + 163.1503

    #ABS = absJudge(ABS)
    ABS = 110

    return ABS, speedr


count = 0
#s = Server(HOST, PORT)
imgProc = processImage()
time.sleep(1)
firstStart = True
prevEdgeL = 0
lastEdge_L, lastEdge_R = 0, 0
lastEdgeTop_L, lastEdgeTop_R = 0, 0
try:
    with picamera.PiCamera(resolution='VGA') as camera:
        with io.BytesIO() as stream:
            for frame in camera.capture_continuous(stream,
                                                   format='jpeg',
                                                   use_video_port=True):
                #aa = time.time()
                stream.seek(0)
                image = Image.open(stream)
                im = np.array(image)