示例#1
0
	def jiekou1(url):#接口1
		try:
			print '\033[1;38;1m Is requesting an interface, the process will be a bit slow \033[0m'
			canshu  = {'b2': 1, 'b3': 1,'b4' : 1,'domain':url}
			html = simple.simple().h_post_text('http://i.links.cn/subdomain/',canshu)
			r = r'<input type=hidden name=[a-z0-9]+ id=[a-z0-9]+ value="([\S]+)">';
			html2 = re.findall(r,html);
			return html2;
		except Exception,e: #如果请求失败 就再请求一次
			try:
				time.sleep(2);
				canshu  = {'b2': 1, 'b3': 1,'b4' : 1,'domain':url}
				html = simple.simple().h_post_text('http://i.links.cn/subdomain/',canshu)
				r = r'<input type=hidden name=[a-z0-9]+ id=[a-z0-9]+ value="([\S]+)">';
				html2 = re.findall(r,html);
				return html2;
			except Exception,e: #如果请求失败 就再请求一次 还失败 就返回空
				try:
					time.sleep(2);
					canshu  = {'b2': 1, 'b3': 1,'b4' : 1,'domain':url}
					html = simple.simple().h_post_text('http://i.links.cn/subdomain/',canshu)
					r = r'<input type=hidden name=[a-z0-9]+ id=[a-z0-9]+ value="([\S]+)">';
					html2 = re.findall(r,html);
					return html2;
				except Exception,e:
					print e;
					aaa = [];
					return aaa;
示例#2
0
 def jiekou1(url):  #接口1
     try:
         print '\033[1;38;1m Is requesting an interface, the process will be a bit slow \033[0m'
         canshu = {'b2': 1, 'b3': 1, 'b4': 1, 'domain': url}
         html = simple.simple().h_post_text('http://i.links.cn/subdomain/',
                                            canshu)
         r = r'<input type=hidden name=[a-z0-9]+ id=[a-z0-9]+ value="([\S]+)">'
         html2 = re.findall(r, html)
         return html2
     except Exception, e:  #如果请求失败 就再请求一次
         try:
             time.sleep(2)
             canshu = {'b2': 1, 'b3': 1, 'b4': 1, 'domain': url}
             html = simple.simple().h_post_text(
                 'http://i.links.cn/subdomain/', canshu)
             r = r'<input type=hidden name=[a-z0-9]+ id=[a-z0-9]+ value="([\S]+)">'
             html2 = re.findall(r, html)
             return html2
         except Exception, e:  #如果请求失败 就再请求一次 还失败 就返回空
             try:
                 time.sleep(2)
                 canshu = {'b2': 1, 'b3': 1, 'b4': 1, 'domain': url}
                 html = simple.simple().h_post_text(
                     'http://i.links.cn/subdomain/', canshu)
                 r = r'<input type=hidden name=[a-z0-9]+ id=[a-z0-9]+ value="([\S]+)">'
                 html2 = re.findall(r, html)
                 return html2
             except Exception, e:
                 print e
                 aaa = []
                 return aaa
示例#3
0
def word(img):
    large = img

    # rgb = cv2.pyrDown(large)
    rgb = large
    small = cv2.cvtColor(rgb, cv2.COLOR_BGR2GRAY)

    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2, 2))
    grad = cv2.morphologyEx(small, cv2.MORPH_GRADIENT, kernel)

    _, bw = cv2.threshold(grad, 0.0, 255.0,
                          cv2.THRESH_BINARY | cv2.THRESH_OTSU)

    kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))  #(9, 1)
    connected = cv2.morphologyEx(bw, cv2.MORPH_CLOSE, kernel)
    # using RETR_EXTERNAL instead of RETR_CCOMP
    Contours, hierarchy = cv2.findContours(connected.copy(), cv2.RETR_EXTERNAL,
                                           cv2.CHAIN_APPROX_NONE)
    #For opencv 3+ comment the previous line and uncomment the following line
    #_, contours, hierarchy = cv2.findContours(connected.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

    mask = np.zeros(bw.shape, dtype=np.uint8)

    # Contours = contours.sort_contours(Contours, method="left-to-right")[0]

    Contours.sort(key=lambda x: get_contour_precedence(x, large.shape[1]))

    for idx in range(len(Contours)):
        x, y, w, h = cv2.boundingRect(Contours[idx])
        mask[y:y + h, x:x + w] = 0
        cv2.drawContours(mask, Contours, idx, (255, 255, 255), -1)
        r = float(cv2.countNonZero(mask[y:y + h, x:x + w])) / (w * h)

        if r > 0.45 and w > 9 and h > 9:
            # cv2.rectangle(rgb, (x, y), (x+w-1, y+h-1), (0, 255, 0), 2)
            imgWordCroped = rgb[y:y + h, x:x + w]

            # cv2.imshow('imgWordCroped', imgWordCroped)

            # Crop characrer
            simple(imgWordCroped)
            # Nhận biết đã kết thúc một từ để chèn dấu cách vào
            signalToTheEndOfAWord('end')

            # cv2.waitKey(0)
        if cv2.waitKey(20) & 0xFF == 27:
            cv2.destroyAllWindows()
            break
示例#4
0
    def test_OrdenarLista(self):
        lista = simple.simple()
        l_ord = simple.ordenar(lista)

        joven = l_ord[0]["edad"]
        viejo = l_ord[-1]["edad"]

        self.assertGreater(viejo, joven)
示例#5
0
 def overlapping(self,rect, zoom=-1):
     # prevents a memory leak...
     # rtree doesn't release the memory until we've 
     # accessed all elements in the generator
     offsets = list(self.idx.intersection(rect))
     s = self.source
     if zoom > -1:
         for o in offsets:
             yield o,simple(s.get(o), zoom)
     else:
         for o in offsets:
             yield o,s.get(o)
示例#6
0
def simple_test():
    os.system("sudo mn -c")

    filename = ctime()

    network = "simple"
    host1 = "h1"
    host2 = "h2"
    switch1 = "s1"
    switch2 = "s2"
    net = startup(simple())

    testing(net, filename, host1, host2, switch1, switch2, network)
    net.stop()
示例#7
0
def renderTile(tx, ty, zoom, polygons, borders = True, width = 256, height = 256):
    """
    renderTile -- return a numpy array of uint32
    
    tx -- tile x coord
    ty -- tile y coord
    zoom -- tile zoom
    polygon -- a polygon locator
    """
    # FORMAT_ARGB32 is premultiplied, which results in loss of precision and thus cannot be used.
    # FORMAT_RGB30 offers up 30bits, (1 billion uniques), 
    #               but isn't available until 1.12 (we have 1.10)
    # FORMAT_RGB24 will have to be used.
    # Another option would be to render a 2nd channel with the alpha info.
    #borders = False
    surface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
    ctx = getContext(surface, tx, ty, zoom)
    bsurface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
    ctx2 = getContext(bsurface, tx, ty, zoom)
    simple_level = zoom if zoom < 10 else -1
    extents = ctx.clip_extents()
    for pid in polygons.overlapping(extents):
        polygon = polygons.source.get(pid)
        if simple_level > -1:
            polygon = simple(polygon, zoom)
        drawPoly(ctx, ctx2, polygon, pid)
    #if borders:
    #    for width in range(10,0,-1):
    #        ctx2.set_source_rgb(0.0,0.0,width/256.)
    #        width = width/ctx2.get_matrix()[0]
    #        ctx2.set_line_width(width)
    #        ctx2.stroke_preserve()
    surface.flush() #make sure operations are finished
    #surface.write_to_png ("example.png") # Output to PNG
    a = numpy.frombuffer(surface.get_data(), 'uint32') & 0x00ffffff
    surface.finish()
    if borders:
        bsurface.flush()
        b = numpy.frombuffer(bsurface.get_data(), 'uint32') & 0x00ffffff
        #bsurface.write_to_png ("example2.png") # Output to PNG
        bsurface.finish()
        return a,b
    # get_data returns buffer
    # FORMAT_RGB24 consists of 32bit pixel in system byteorder
    # as A,R,G,B values.
    # The Alpha channel is present but unused, however
    # it still contains data and must be zeroed.
    return a,None
示例#8
0
def extract_from_config(cfg):
    method = cfg.get('extract', 'method')
    if method == 'simple':
        pre = cfg.getint('detect', 'pre')
        post = cfg.getint('detect', 'post')

        return lambda readers, indices, ffunc: \
                simple.simple(readers, indices, ffunc, pre, post)
    elif method == 'cubic':
        pre = cfg.getint('detect', 'pre')
        post = cfg.getint('detect', 'post')
        direction = cfg.get('detect', 'direction')
        oversample = cfg.getfloat('detect', 'oversample')

        return lambda readers, indices, ffunc: cubic.cubic(readers, indices, \
                ffunc, pre, post, direction, oversample)
    else:
        raise ValueError("Unknown extract method: %s" % method)
示例#9
0
    # best_chromosome, obj_min_history, obj_mean_history, obj_max_history = \
    #     es2(mu, lambda_, polygons, init_number_of_polygons, img_shape,
    #         'Mona_Lisa.png', number_of_iterations=iterations, init_load='')

    # best_chromosome, obj_min_history, obj_mean_history, obj_max_history, = \
    #     SGA(100, polygons, 3, img_shape, 'Mona_Lisa.png', 200, number_of_iterations=iterations)

    # d = polygons * 10
    # best_chromosome, obj_min_history, obj_mean_history, obj_max_history, sigmas_history = \
    #     es(500, polygons, 3, img_shape, 'Mona_Lisa.png', 1000, 0.07,
    #        1/np.sqrt(2*d), 1/np.sqrt(2*np.sqrt(d)), number_of_iterations=iterations)

    wdir = 'history/local2/'
    best_chromosome, obj_min_history, obj_mean_history, obj_max_history = \
        simple(mu, lambda_, polygons, init_number_of_polygons, img_shape,
            'Mona_Lisa.png', number_of_iterations=iterations, init_load=True, wdir=wdir)

    best_chromosome.dump(wdir + 'best_chromosome')
    obj_min_history.dump(wdir + 'obj_min_history')
    obj_mean_history.dump(wdir + 'obj_mean_history')
    obj_max_history.dump(wdir + 'obj_max_history')

    plt.plot(np.arange(iterations), obj_min_history, label='min')
    plt.plot(np.arange(iterations), obj_max_history, label='mean')
    plt.plot(np.arange(iterations), obj_mean_history, label='max')
    plt.legend()
    plt.show()
    # plt.plot(np.arange(iterations), sigmas_history, label='sigmas')
    # plt.legend()
    # plt.show()
示例#10
0
文件: putty.py 项目: rogual/po
import simple
import standard
import environment

url = "http://the.earth.li/~sgtatham/putty/latest/x86/putty.zip"

recipe = simple.simple('putty', 'PuTTY', url)

@environment.executables.implement(recipe)
def bin(package):
    return [package[standard.a_location]]
示例#11
0
 def test_Lista(self):
     lista = simple.simple()
     self.assertEqual(type(lista), list)
     self.assertEqual(len(lista), 10)
示例#12
0
import simple
import numpy

a = numpy.array([[10., 1, 1, 12], [2, 10, 1, 13], [2, 2, 10, 14]])
print('Исходная матрица:')
print(a)
print("\n")

b = simple.simple(a)
示例#13
0
def drawPolygons(drawOn,
                 polygons,
                 ratioWidth,
                 ratioHeight,
                 color=(0, 0, 255),
                 width=1):
    # # print("polygons: " + str(len(polygons))) #các khung nhận dạng được trong 1 hình

    for polygon in polygons:
        pts = np.array(polygon, np.int32)
        pts = pts.reshape((-1, 1, 2))

        #### draw the polygon
        # img = cv2.polylines(drawOn, [pts], True, color, width)

        ####
        # print("pts: "+ str([pts][1]))   https://www.aiworkbox.com/lessons/convert-numpy-array-to-mxnet-ndarray
        # print("pts: "+ str([pts(1)]))

        # points = [
        #     (upperLeftX, upperLeftY),
        #     (lowerRightX, upperLeftY),
        #     (lowerRightX, lowerRightY),
        #     (upperLeftX, lowerRightY)
        # ]

        # ===========================
        # # Cắt ảnh từ khung nghiêng
        # # print("polygon[3][1]: "+ str(polygon[3][1])) #246.98870153288397
        # # print("polygon[1][1]: "+ str(polygon[1][1])) #195.3879830750784
        # # print("polygon[3][0]: "+ str(polygon[3][0])) #222.65554937590102
        # # print("polygon[1][0]: "+ str(polygon[1][0])) #360.8632403870683
        # rect_img1 = drawOn[int(polygon[1][1]) : int(polygon[3][1]), int(polygon[3][0]) : int(polygon[1][0])]
        # cv2.imshow('rect_img1', rect_img1)

        # ===========================
        # Given 4 points, how to crop a quadrilateral from an image in pytorch/torchvision?
        # polygon[0][0] = polygon[0][0] - 2
        # polygon[0][1] = polygon[0][1] - 10
        # polygon[1][0] = polygon[1][0] + 5
        # polygon[1][1] = polygon[1][1] - 10
        # polygon[2][0] = polygon[2][0] + 5
        # polygon[2][1] = polygon[2][1] + 10
        # polygon[3][0] = polygon[3][0] - 2
        # polygon[3][1] = polygon[3][1] + 10
        # pts = np.array([[polygon[0][0] - 5, polygon[0][1] - 5], [polygon[1][0] + 5, polygon[1][1] - 5], [polygon[2][0] + 5, polygon[2][1] + 5], [polygon[3][0] - 5, polygon[3][1] + 5]], dtype=np.int32)
        pts = np.array(
            [[polygon[0][0], polygon[0][1]], [polygon[1][0], polygon[1][1]],
             [polygon[2][0], polygon[2][1]], [polygon[3][0], polygon[3][1]]],
            dtype=np.int32)
        # # Text xoay hình
        # img_crop = cropImage(drawOn, polygon, pts)

        img_crop = scanFromPoint(pts, drawOn, 100)

        # filename1 = './images/croped/croped-' + str(polygon[0][1]) + str(polygon[1][1])  + '.jpg'
        # cv2.imwrite(filename1, img_crop)

        cv2.imshow("img_crop", img_crop)
        simple(img_crop)
        signalToTheEndOfAWord('end')
示例#14
0
文件: unixutils.py 项目: rogual/po
from os.path import join
import simple
import standard

url = "http://downloads.sourceforge.net/project/" \
      "unxutils/unxutils/current/UnxUtils.zip"

# Windows requres admin privileges to run any file with "patch" in its name
# unless it has a manifest like this.
manifest = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
"""

recipe = simple.simple('unixutils', 'Unix Utilities', url)

@standard.installer.implement(recipe)
def do_install(package):
    path = simple.download_and_extract(url, package)
    mpath = join(path, 'usr', 'local', 'wbin', 'patch.exe.manifest')
    with open(mpath, 'wt') as file:
        file.write(manifest)
示例#15
0
文件: cef.py 项目: rogual/po
from os.path import join

import simple
import environment
import standard

url = "https://chromiumembedded.googlecode.com/" \
      "files/cef_binary_1.1180.832_windows.zip"

recipe = simple.simple('cef', 'Chromium Embedded Framework', url)


@environment.libraries.implement(recipe)
def libraries(package):
    loc = package[standard.a_location]
    return [join(loc, 'lib', 'Release'), join(loc, 'Release', 'lib')]


@environment.headers.implement(recipe)
def include(package):
    loc = package[standard.a_location]
    return [loc, join(loc, 'include')]
示例#16
0
文件: scons.py 项目: rogual/po
from os.path import join

import simple
import environment
import standard
import subprocess

url = "http://sourceforge.net/projects/" \
      "scons/files/scons/2.2.0/scons-2.2.0.tar.gz"

recipe = simple.simple('scons', "SCons", url)


@environment.executables.implement(recipe)
def bin(package):
    return [join(package[standard.a_location], 'Scripts')]


@environment.pythonpath.implement(recipe)
def pypath(package):
    return [join(
        package[standard.a_location], 'Lib', 'site-packages', 'scons-2.2.0'
    )]


@standard.installer.implement(recipe)
def do_install(package):
    path = simple.download_and_extract(url, package)
    ret = subprocess.call(
        'python setup.py install --prefix=%s' % path,
        shell=True,