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 edb93e31a6b495451ddb933328d7b8098d2348eb..ba0789fdecbb4eacfaf633ba8c9741ae5c39e8ab 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 d8af8a92c45cf2ab68f468607eb6420501ebde09..53f071500947519b97599f1651f81f5a1eb94104 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 0000000000000000000000000000000000000000..21320803a75f450f74dff064bd0f7bbea23a661f --- /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)