From c9c8dc6241e702cb503f96829eda56cfb795bf9e Mon Sep 17 00:00:00 2001 From: feilong Date: Fri, 17 Dec 2021 17:28:34 +0800 Subject: [PATCH] fix png --- .../connect.md" | 4 +- main.py | 12 ++++-- src/img.py | 40 +++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 src/img.py diff --git "a/data/1.OpenCV\345\210\235\351\230\266/2.\344\272\214\345\200\274\345\233\276\345\203\217\345\244\204\347\220\206/4.\350\277\236\351\200\232\345\214\272\345\237\237\345\210\206\346\236\220/connect.md" "b/data/1.OpenCV\345\210\235\351\230\266/2.\344\272\214\345\200\274\345\233\276\345\203\217\345\244\204\347\220\206/4.\350\277\236\351\200\232\345\214\272\345\237\237\345\210\206\346\236\220/connect.md" index edb93e3..ba0789f 100644 --- "a/data/1.OpenCV\345\210\235\351\230\266/2.\344\272\214\345\200\274\345\233\276\345\203\217\345\244\204\347\220\206/4.\350\277\236\351\200\232\345\214\272\345\237\237\345\210\206\346\236\220/connect.md" +++ "b/data/1.OpenCV\345\210\235\351\230\266/2.\344\272\214\345\200\274\345\233\276\345\203\217\345\244\204\347\220\206/4.\350\277\236\351\200\232\345\214\272\345\237\237\345\210\206\346\236\220/connect.md" @@ -2,11 +2,11 @@ OpenCV 里的连通区域分析可以将具有相同像素值且位置相邻的前景像素点组成的图像区域识别出来。有两种像素相邻的定义: -![](./pixel_region.jpg) +![](data/1.OpenCV初阶/2.二值图像处理/4.连通区域分析/pixel_region.jpg) 通过OpenCV的连通区域分析算法,我们可以将下图的水鸭子的外框框出来: -![](./duck_box.png) +![](data/1.OpenCV初阶/2.二值图像处理/4.连通区域分析/duck_box.png) 框架代码如下: diff --git a/main.py b/main.py index d8af8a9..53f0715 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- from src.tree import TreeWalker from src.doc import DocWalker +from src.img import ImgWalker if __name__ == '__main__': - walker = TreeWalker("data", "opencv", "OpenCV") - walker.walk() + # walker = TreeWalker("data", "opencv", "OpenCV") + # walker.walk() - doc = DocWalker('doc') - doc.walk() + # doc = DocWalker('doc') + # doc.walk() + + img = ImgWalker('data') + img.walk() diff --git a/src/img.py b/src/img.py new file mode 100644 index 0000000..2132080 --- /dev/null +++ b/src/img.py @@ -0,0 +1,40 @@ +import os +from sys import path, version +from types import new_class +from .tree import load_json, dump_json + + +def simple_list_md_load(p): + with open(p, 'r', encoding='utf-8') as f: + lines = f.readlines() + result = [] + for line in lines: + item = line.strip('\n') + result.append(item) + return result + + +def simple_list_md_dump(p, lines): + with open(p, 'w', encoding='utf-8') as f: + f.write('\n'.join(lines)) + + +class ImgWalker(): + + def __init__(self, root) -> None: + self.root = root + + def walk(self): + for base, dirs, files in os.walk(self.root): + for file in files: + if file[-3:] == '.md': + md_file = os.path.join(base, file) + md_lines = simple_list_md_load(md_file) + md_new = [] + for line in md_lines: + new_line = line.replace('![](./', f'![]({base}/') + md_new.append(new_line) + md_new.append('') + simple_list_md_dump(md_file, md_new) + import sys + sys.exit(0) -- GitLab