串口DMPL指令刻字机自动识别图形轮廓并刻绘py
来源:互联网 发布:电影制作软件 编辑:程序博客网 时间:2024/03/29 05:31
#coding=utf-8"""作者:JoshuaQQ:445621012"""import cv2import Imageimport numpy as npimport serialimport sysimport mathimport osdef getinfo(path):img = cv2.imread(path)gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #把图像转换成灰度图ret, binary = cv2.threshold(gray,127,255,cv2.THRESH_BINARY) #hold the binarycontours, hierarchy = cv2.findContours(binary,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) #find edgesdel(contours[0]) #删除numpy数组中最外层的轮廓#print contourscv2.drawContours(img,contours,-1,(13,52,163),5) #draw the contours#找到横坐标的最小值和最大值,为以后设定大小做准备left=[]right=[]top=[]foot=[]for c in contours:pentagram = cleftmost = tuple(pentagram[:,0][pentagram[:,:,0].argmin()])rightmost = tuple(pentagram[:,0][pentagram[:,:,0].argmax()])topmost = tuple(pentagram[:,0][pentagram[:,:,1].argmin()])footmost = tuple(pentagram[:,0][pentagram[:,:,1].argmax()])l=leftmost[0]r=rightmost[0]t=topmost[0]f=footmost[0]left.append(l)right.append(r)top.append(t)foot.append(f)print left,"\n",right,"\n",top,"\n",footleftm=min(left)rightm=max(right)topm=min(top)footm=max(foot)print '\npeak at:',leftm,rightm,topm,footm#画出矩形(x, y, w, h) = cv2.boundingRect(contours[0])cv2.rectangle(img,(leftm, y), (rightm, y + 2), (0, 255, 0), 1)print "hhhhhh"print (rightm-leftm)#print "width is:",(rightm-leftm)#print "size of the original imageis :",im.sizecv2.imshow("img", img)cv2.waitKey(0)return (leftm,rightm,(rightm-leftm),topm,footm)def vecnzo(ob,size):image=cv2.imread(ob)info=getinfo(path)height,width=image.shape[:2]w=info[2]rate=float(255)/float(w)rate2=13.68*size/9gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) #转换成灰度图es=cv2.resize(gray,(int(width*rate*rate2),int(height*rate*rate2)),interpolation=cv2.INTER_CUBIC)ret, binary = cv2.threshold(es,127,255,cv2.THRESH_BINARY) #hold the binary[gray]contours, hierarchy = cv2.findContours(binary,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) #查找边缘del(contours[0]) #删除numpy数组中最外层的轮廓perimeter = cv2.arcLength(contours[0],True)print "longth %s"%perimeterprint type(contours[0])file=open("1.txt","w")file.write(";:H A L0 ECN U V10") #初始化高精度绘图仪for c in contours:file.write(" ")a=0file.write(" U")for d in c:for tables in d:for item in tables:file.write(str(item))a+=1if(a==2):file.write(" D")else:file.write(",")tail=c[0][0]file.write(str(tail[0]))file.write(",")file.write(str(tail[1]))a=0file.close()#grave()def grave():file = open("1.txt","r")con = file.read()t = serial.Serial('com1',9600)n = t.write(con)path="1.jpg"print "get your image cut and put you image file here then name it 1.jpg\n"size=float(raw_input("input the size you want your grave be alright! :"))vecnzo(path,size)os.system("pause")由于家里开的印刷厂,近年改了方法,对于要求不非常细致的丝网印刷单子,就用刻字机刻黏纸,然后直接贴在版上,不用再感光什么的编程语言就是给懒人准备的由于接了单子还要用photoshop处理成对比度高的,细节清楚,高像素的位图,然后再用刻字机自带的软件识别现在什么都不用做了,只要准备好压缩图,不用位图,设定好大小,就刻出来了用到了python第三方库opencv numpy还有serial源代码在百度网盘http://pan.baidu.com/s/1eSmN8Gi没什么技术含量,但是用起来很方便,简化了很多人工步骤,只是还没想出方案实现一个功能,就是在轮廓数组中识别直线,矩形,以及设置精度舍弃一些多余的点,等大学学了高数再说吧嘿嘿
阅读全文
0 0
- 串口DMPL指令刻字机自动识别图形轮廓并刻绘py
- 枚举所有串口,并自动识别硬件变动
- VC6.0 自动识别可用串口 添加至combox 并打开
- VC6.0 自动识别可用串口 添加至combox 并打开
- opencv绘制图形轮廓并筛选面积操作
- 自动识别图形验证码
- 自动识别图形验证码
- 自动识别图形验证码
- 自动识别图形验证码
- 自动识别图形验证码
- 自动识别串口号
- MFC自动识别串口
- 串口注册表的自动识别
- 使用VC6.0 自动识别可用串口 添加至combox 并打开。
- PS提取图形轮廓
- wins下串口 的自动识别
- MATLAB利用串口接收数据,并实时显示图形
- 大理石刻字
- Android异步任务机制之AsycTask
- Thread+Handler异步执行耗时操作更新UI线程界面
- Java1.8新特性 Lambda/Stream/函数式编程
- Dialog全屏设置
- B
- 串口DMPL指令刻字机自动识别图形轮廓并刻绘py
- 拼多多面试
- go 基础,go path go isntall
- 算法应用新篇
- html css 制作出翻页的时候慢慢的出来,或者放大缩小
- Linux 网络编程——TCP 粘包及其解决方案
- HashCode的理解与应用
- MATLAB2015b链接MinGW编译器
- 【NOIP模拟赛三】并查集+hash day2 third 雪后村庄(好题)