Beispiel #1
0
def suckBG(u,url):
    "download the graphic, check for unique md5, save to unique filename"
    global bgBytes
    bget = None
    if u not in backgrounds and u not in tmp_backgrounds:
        try:
            bget = urllib.urlopen(u)
            if bget.info().getheader("Content-Type") and bget.info().getheader("Content-Type") != "image/jpeg" and bget.info().getheader("Content-length") < 15000 :
                "Let's be sure that we dont download image before knowing everything about it"
                print "+got image"
                bget.close()
                return
            else:
                btmp = bget.read()
                md = hashlib.md5(btmp).hexdigest()
        except Exception: 
            print "-couldn't download this picture"
            return
        if md not in md5s and md not in tmp_md5s :
                fn = getFileName(u,len(btmp))
                if fn: #if we have our image filename
                    fbg = open(fn,'wb') #open file for writing
                    fbg.write(btmp) # write it
                    fbg.close() #close it
                    bgBytes = bgBytes + len(btmp) #count size
                    fileHandler = Image.open(fn) #open file for analysis
                    fn_jpeg = fn
                    height = hlsir.reportShapeInfo(fn_jpeg)[1] 
                    width = hlsir.reportShapeInfo(fn_jpeg)[0]
                    if fileHandler.format == 'JPEG' and fileHandler.mode == 'RGB' and hlsir.reportShapeInfo(fn_jpeg)[0]>128 and hlsir.reportShapeInfo(fn_jpeg)[0]<1600 and hlsir.reportShapeInfo(fn_jpeg)[1]>128 and hlsir.reportShapeInfo(fn_jpeg)[1]<1600:
                        for x in range(0,sliceX):
                            for y in range(0,sliceY):
                                [h,l,s] = hlsir.convertJpgToHlsNumpy(fn_jpeg,x,y) # if hls is zero than image was too small
                                HLS_VECTOR[x,y] = [h,l,s]   
                        """print "This is HLS : %s " % (HLS_VECTOR)     """
                        print "\033[1m +vector commit! \033[0m"
                        hlsir.mysqlInsertImage(md,fn_jpeg,height,width,u,url,HLS_VECTOR)
                        hlsir.repetitiveness = 0
                        tmp_md5s.append(md)
        else:
            print "Inapropriate format of file"       
    else:
        print chrDupe+" MD5 fingerprint for '%s' exists." % u[string.rfind(u,'/')+1:]
Beispiel #2
0
                        idx+=1
            """print "Importance matrix : %s" % (importance_matrix)"""
            
            o = open(dirUpload+os.sep+fn,"wb")
            o.write(data[key].value)
            o.close()

            fnList.append(fn)
            imagefile = dirUpload+os.sep+fn
            fileHandler = Image.open(imagefile)
            if fileHandler.format != "JPEG" or fileHandler.mode != "RGB":
                print "Invalid fileformat"
                sys.exit(0)
            else:
                file_jpeg = imagefile
                height = hlsir.reportShapeInfo(imagefile)[1] 
                width = hlsir.reportShapeInfo(imagefile)[0]
           
            a = time.time()
            for x in range(0,hlsir.sliceX):
                for y in range(0,hlsir.sliceY):
                    [H,L,S] = hlsir.convertJpgToHlsNumpy(file_jpeg,x,y)
                    HLS_VECTOR[x,y] = [H,L,S]
            
            print "<br><h1>Source image</h1><br> <img src=upload/%s width=20%% height=20%%>" % (fn)
            """ method 1 """
            
	    basetreshold = 0.95
	    iterator = 0.05
	    imagescount = 0
	    imagescount = hlsir.HLSQueryCount(HLS_VECTOR,basetreshold,basetreshold,basetreshold,importance_matrix,basetreshold)