python+Opencv学习教程01:图像腐蚀与膨胀操作

1 读取或写出中文路径

首先python的opencv函数对中文支持不太友好。例如:imread()和imwrite()就不能写中文。

这里对这两个方法进行改造,使之支持中文文件名。

def cv_imwrite(filename,img):
    '''
    :param filename: 要写出的文件名
    :param img: 要写出的图像数据
    :return: 无
    '''
    cv2.imencode(ext='.jpg',img=img)[1].tofile(filename)
def cv_imread(file_path):
    '''
    :param file_path: 读入的图像文件路径
    :return: 读入的图像数据
    '''
    cv_img=cv2.imdecode(np.fromfile(file_path,dtype=np.uint8),flags=cv2.IMREAD_GRAYSCALE)
    return cv_img

imshow()的标题也不支持中文,一个蹩脚且偶然可行的方案:

cv2.imshow(winname="原图".encode('gbk').decode(errors='ignore'), mat=src)

2 腐蚀操作源代码

 2.1 erode方法与

def erode(src: Any,
    &n

Python图像处理丨图像腐蚀与图像膨胀 本篇文章主要讲解Python调用OpenCV实现图像腐蚀和图像膨胀的算法,基础性知识希望对您有所帮助。图像的膨胀(Dilation)和腐蚀(Erosion)是两种基本的形态学运算,主要用来寻找图像中的极大区域和极小区域。其中膨胀类似于“领域扩张”,将图像中的高亮区域或白色部分进行扩张,其运行结果图比原图的高亮区域更大;腐蚀类似于“领域被蚕食”,将图像中的高亮区域或白色部分进行缩减细化,其运行结果图比原图的高亮区域更小。... 阅读详情

相关推荐

AutoModelForCausalLM 加载失败:flash_attn 缺失的三种解决方案

本文针对使用AutoModelForCausalLM加载大语言模型时因缺失flash_attn依赖而报错的问题,提供了三种实用解决方案。最推荐通过修改模型配置文件或代码动态指定注意力实现为“eager”模式来绕过检查,也介绍了临时修改库源码的应急方法,并解释了flash_attn的作用及正确安装指南。

html8的博客 269

K210开发板学习笔记(三)——STM32+K210+SD卡实现人脸识别(完整K210代码)

更新日记:2022年4月26日 更新了串口通信部分的内容,本文写的略为粗糙,恐有不当之处,希望大家不吝赐教。 人脸识别 一、MaixPy IDE开发 参考博主晨少hc的博文(https://blog.youkuaiyun.com/HuangChen666/article/details/113995079)来实现人脸识别功能,我用的硬件是亚博智能的K210开发板,在配置工程中有几步和这个博主的不一样,需要注意。 所需要的文件有:模型文件),脚本文件,ide需要的bin文件...

Embedded learner的博客 4万+

【速通版!语义通信基础与前沿学习计划】

🧠语义通信基础与前沿学习计划

dally2的博客 1412

Plant simulation、Flexsim、Automod、Emulate3D、VisuaComponent仿真软件对比

E3D在行业内以展示效果好,入门阶段易学易用人机界面友好,电控仿真连接方便不需要借助其他第三方软件,E3D平台开放度较高用户DIY程度强,数据分析功能针对要评定对象的KPI的可根据项目或者使用者需求进行评定。3.支持导入导出多种格式的文件,比如dwg、dxf、fbx、obj、3ds、step、stp、iges、skp、stl、wrl、 bmp 等等。3.软件自带模型组件库程序代码开放,用户可以引用、修改、拷贝,按照自己的逻辑修改模型,或者创建模型并保存到组件库与别人共享。3. 支持导出布局图片。

qq_43342303的博客 3578

堆内存管理核心逻辑 超详细复习笔记

本文详细解析了堆内存管理的核心逻辑,包括初始化、分配和释放三个关键环节。系统通过全局堆管理结构体和链表机制实现动态内存管理:初始化时标记整块内存为空闲;分配时遍历链表查找合适空闲块并进行分割;释放时定位内存块头并重新标记为空闲,支持相邻块合并以减少碎片。文章对比了链表式管理和线性分配的优缺点,指出链表式更灵活但实现复杂,线性分配简单但无法释放。最后总结了常见错误(如指针回推错误、碎片问题)和扩展知识(不同内存管理算法)。这套机制是理解嵌入式系统和RTOS内存管理的基础。

2502_92009732的博客 1197

PCB工艺-SI9000使用教程

本文介绍了阻抗计算工具SI9000的使用方法,重点讲解了微带线与带状线的区别、共面阻抗概念及参考面选择。通过USB差分走线实例,详细说明了如何选择计算模型、填写参数并确定线宽线距。文章还提供了层叠设计资料和工厂常规阻抗表格作为参考,建议制板时标注需控阻抗的线路供板厂调整。最后简单提及了嘉立创阻抗计算工具作为备选方案。

weixin_50120208的博客 2024

在 Visual Studio Code 中开发 SAP Fiori 应用并部署到 Cloud Foundry 的完整实战指南

摘要:本文介绍如何以ABAP RAP服务为后端,通过VS Code和SAP Fiori工具将Fiori应用一键部署到SAP BTP Cloud Foundry环境。主要内容包括:1) 开发环境配置(VS Code+Fiori工具);2) 架构流程说明(MTA打包、Approuter路由);3) 权限准备(业务Catalog分配);4) 创建带Approuter的MTA项目;5) 连接ABAP OData服务并生成Fiori应用。文中还针对常见问题(如服务不可见、部署失败)提供了解决方案参考。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 364

七天征服AutoSAR/SomeIP_01速成配置并代码生成

本文为AutoSAR中SomeIP配置开发的实操指南摘要,重点介绍通过通信矩阵快速构建SomeIP工程的方法。核心内容包括:1)基于Excel通信矩阵生成系统描述文件(arxml);2)在AutoSAR工具中导入文件自动生成协议栈配置,涵盖ETHIF、SoAd等模块;3)关键报错处理(COM/PDUR/SOAD/SD模块的配置修正);4)SomeIPXF的数据编解码配置;5)SWC组件与RTE任务映射。教程强调"先完成再完美"的实践原则,指导开发者快速生成基础代码框架,为后续协议调试奠定

大叔带刺的博客 303

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

上一篇: C#编程学习49:将数据写入到excel中
下一篇: python+Opencv学习教程02:图像形态学操作(开、闭、梯度、礼帽、黑帽运算)
薛桂琴
博客等级 码龄11年 4万+粉丝 359原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薛桂琴

喜欢的读者,可以打赏鼓励一下

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值