首页/文章/ 详情

code分享

27天前浏览581
    proc CreateImageFile {args} {set python_script { from PIL import Image, ImageSequenceimg = Image.open(r"C:\Users\jintian\Downloads\5.gif")black_pixels = []for frame in ImageSequence.Iterator(img):    frame = frame.resize((300, 300))    frame = frame.convert('1')    black_pixels_frame = [y * frame.width + x + 1 for y in range(frame.height) for x in range(frame.width) if frame.getpixel((x, y)) == 0]    black_pixels.append(black_pixels_frame)# Open the filewith open(r"C:\Users\jintian\Downloads\5.txt", 'w') as f:    for black_pixels_frame in black_pixels:        positions_str = [str(id) for id in black_pixels_frame]        line = ' '.join(positions_str)        f.write(line + '\n')print (r"C:\Users\jintian\Downloads\5.txt")}cd "D:/Users/jintian/anaconda3"set result [exec python << $python_script]return $result}# CreateImageFileset ImageInfoPath [CreateImageFile]  for {set i 0} {$i < 10} {incr i} {    set f [open $ImageInfoPath]    while {1} {      set line [gets $f]      if {[eof $f]} {        close $f        break      }      *createmark elem 1   {*}$line      hm_highlightmark Elements 1 high;      *window 0 0 0 0 0      after 10    }  }
    来源:TodayCAEer
    ADSpython
    著作权归作者所有,欢迎分享,未经许可,不得转载
    首次发布时间:2024-08-14
    最近编辑:27天前
    TodayCAEer
    本科 签名征集中
    获赞 16粉丝 8文章 163课程 0
    点赞
    收藏
    作者推荐

    整活是一个没约束的状态,就像自由模态,你不知道会返回多少阶。

    之前对于cv2模块是不熟悉,实际上修改识别文字那一篇在整活的道路上,一去不复返cv2.findContours函数的第二个参数,将cv2.RETR_EXTERNAL改为cv2.RETR_CCOMP即可以同时获取内外轮廓。获取的轮廓后还是同样的,基于轮廓点创建样条线,再创建曲面,保留区域面积最大的surface,其余surface将作为裁剪曲面,裁剪最大的surface,即可完成。importcv2importnumpyasnpimg=cv2.imread(&#39;640.jpg&#39;,cv2.IMREAD_GRAYSCALE)_,thresh=cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)contours,hierarchy=cv2.findContours(thresh,cv2.RETR_CCOMP,cv2.CHAIN_APPROX_SIMPLE)withopen(&#39;640output.txt&#39;,&#39;w&#39;)asf:foriinrange(len(contours)):points=contours[i].squeeze().tolist()points_str=[&#39;{},{}&#39;.format(point[0],point[1])forpointinpoints]line=&#39;&#39;.join(points_str)ifhierarchy[0][i][2]!=-1:line+=&#39;++&#39;f.write(line+&#39;\n&#39;)}来源:TodayCAEer

    未登录
    还没有评论
    课程
    培训
    服务
    行家
    VIP会员 学习 福利任务 兑换礼品
    下载APP
    联系我们
    帮助与反馈