博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
可以后退的的截图小工具
阅读量:5012 次
发布时间:2019-06-12

本文共 4613 字,大约阅读时间需要 15 分钟。

# -*- coding: utf-8 -*-"""Created on Fri Jan 17 09:01:01 2014@author: xiaoxia"""# -*- coding: utf-8 -*-"""Created on Wed Jan 15 10:14:43 2014@author: xiaoxia"""import cv2  #将数据存为小图片    def fan() :      f=open("picture.txt","r")    l_2=open("picture2.txt","w")    k = []    u = []    for eachline in f:        eachline = eachline.strip()        eachline = eachline.split("   ")         for i in eachline:                            i = str(i)            k.append(i)            if len(k) == 4:                u.append(k)                k = []            i_mg = cv2.imread("jiangnan.jpg")    i=0    for picture in u :                x = int(picture[0])        y = int(picture[1])        w = int(picture[2])        h = int(picture[3])        i+=1        I_mg = i_mg[y:h,x:w]            c = cv2.imwrite(str(i)+".jpg", I_mg)#    return        for z in u:        for x in z :            x=str(x)            l_2.write(x)            l_2.write("   ")        l_2.write("\n")    l.close()    f.close()#####################################################################             def onMouseEvent(event,x,y,flags,param):      global startPointx         global startPointy       global flagDraw    global i    #鼠标左键按下响应       if(event==1):  #第一点        print "Position is: %d,%d" ,x,y                     startPointx = x         print type(x)        startPointy = y          i=i+1        cv2.putText(image,str(i),(startPointx,startPointy),2,1,(249,99,201))        flagDraw = True                            a = str(x)        b = str(y)        l.write(a)        l.write("   ")        l.write(b)        l.write("   ")                #鼠标移动响应       if(event==0):  #滑动过程        if(flagDraw==True):             imgc = cv2.copyMakeBorder(image,0,0,0,0,cv2.BORDER_CONSTANT)            cv2.rectangle(imgc, (startPointx,startPointy), (x,y), (249,99,201),2)            #cv2.putText(imgc,(x,y),CV_FONT_HERSHEY_PLAIN,2.0,(255,0,0),thickness = 2)                cv2.imshow('rectangle', imgc)                            print "EndPosition is: %d,%d" ,x,y                              #鼠标左键抬起响应      if(event==4):   #第二点        if(flagDraw==True):              cv2.rectangle(image, (startPointx,startPointy), (x,y), (249,99,201),2)              #cv2.imshow('rectangle_1', image)                            flagDraw = False            c = str(x)            d = str(y)            l.write(c)            l.write("   ")            l.write(d)            l.write("   ")########################################################################        image = cv2.imread("jiangnan.jpg")   global startPointx   global startPointy   global flagDrawglobal ii=0   startPointx = 0  startPointy = 0  flagDraw = Falsecv2.namedWindow("rectangle",cv2.WINDOW_NORMAL)#cv2.namedWindow("rectangle_1",cv2.WINDOW_NORcv2.imshow('rectangle',image)                  if __name__ == '__main__':        image = cv2.imread("jiangnan.jpg")    h, w  = image.shape[:2]    imgc = cv2.copyMakeBorder(image, 0,0,0,0, cv2.BORDER_CONSTANT)       # cv2.imshow('rectangle', imgc)      l=open("picture.txt","w")    f=open("picture.txt","r")        while True:          cv2.setMouseCallback('rectangle', onMouseEvent)  #调用滑鼠        c = cv2.waitKey()          if c == 27 or c == ord('q'):                         break          if c == ord('w')  :            print "w"            l.close()            a=[]            b=[]            for eachline in f:                eachline=eachline.strip()                eachline=eachline.split("   ")                 for k in eachline:                            k=str(k)                    b.append(k)                    if len(b)==4:                        a.append(b)                        b=[]                                print a            g=a[:-1]            print g            l=open("picture.txt","w")            f=open("picture.txt","r")                        for t in g:                for k in t :                    k=str(k)                    l.write(k)                    l.write("   ")                l.write("\n")            print "yes:",g            image = cv2.imread("jiangnan.jpg")            ii=0            for q in g:                xa=int(q[0])                ya=int(q[1])                xb=int(q[2])                yb=int(q[3])                ii=ii+1                cv2.putText(image,str(ii),(xa,ya),2,1,(249,99,201))                cv2.rectangle(image, (xa,ya),(xb,yb),(249,99,201),2)                                                               cv2.imshow('rectangle', image)                    l.close()    f.close()    cv2.destroyAllWindows()    fan()

按w可以后退

 

转载于:https://www.cnblogs.com/heizaiaha/p/3524158.html

你可能感兴趣的文章
iOS获取设备IP地址
查看>>
JavaSE| String常用方法
查看>>
NRF51822配对绑定要点
查看>>
C语言博客作业—数据类型
查看>>
HTML“计算机输出”标签 <code><kbd><samp><tt><var><pre>
查看>>
php获取客户端ip get_client_ip()
查看>>
读《死亡诗社》
查看>>
zbb20181219 json,javabean 相互传唤
查看>>
UIPickerView常用属性 -- 小总结
查看>>
学点Groovy来理解build.gradle代码
查看>>
设置宽高等比的盒子
查看>>
SQL2000和SQL2005和SQL2008同时安装问题
查看>>
通过HTTP代理与HOSTS文件的问题
查看>>
PAT1042:Shuffling Machine
查看>>
数据挖掘:实用案例分析
查看>>
《JavaScript网页特效经典300例》
查看>>
UOJ#62. 【UR #5】怎样跑得更快 数论 莫比乌斯反演
查看>>
sybase锁
查看>>
java程序源码
查看>>
MYSQL中的字符串连接符
查看>>