observer pattern

本文深入浅出地介绍了观察者模式的原理与应用。通过报纸订阅的例子生动解释了该模式的工作流程,并展示了Java中如何实现这一设计模式。文章还强调了观察者模式在保持对象间松耦合的重要性。
Observer pattern: defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

oo principles: strive for loosely coupled designs between objects that interact.

How observer pattern works

let's look at how newspaper or magazine subscriptions work:
1. A newspaper publisher goes into business and begins publishing newspapers.
2. You subscribe to a particular publisher, and every time there's a new edition it gets delivered to you. As long as you remain a subscriber, you get new newspapers
3. You unsubscribe when you don't want papers anymore, and they stop being delivered
4. While the publisher remains in business, people, hotels, airlines and other businesses constantly subscribe and unsubscribe to the newspaper.

Publishers+subscribers = observer pattern

if you understand newspaper subscriptions, you pretty much understand the Observer Pattern, only we call the publisher the [b]SUBJECT [/b] and the subscribers the [b]OBSERVERS[/b]

Illustration
[IMG]http://i45.tinypic.com/2jes50k.jpg[/IMG]

the duck object isn't an observer, it wont get notified when the subject's data changes.

How does the duck object become an observer
1. register/subscribe
[IMG]http://i47.tinypic.com/2whkpyp.jpg[/IMG]

2.The duck object is now an official observer
duck is psyched. he's on the list and is waiting with great anticipation for the next notification.
[IMG]http://i45.tinypic.com/fjm9no.jpg[/IMG]

3. the subject gets a new data value
Now duck and all the rest of observers get a notification that the subject has changed
[IMG]http://i48.tinypic.com/309lamc.jpg[/IMG]


java built-in support of observer pattern
[IMG]http://i50.tinypic.com/9is6rp.jpg[/IMG]


bullet point
* The observer pattern defines a one-to-many relationship between objects
* Subjects, or as we also know them, Observables, update Observers using a common interface
* Observers are loosely coupled in that the Observable knows nothing about them, other than that they implement the Observer interface
* You can push or pull data from Observable when using the pattern(pull is considered more "correct")
* Don't depend on a specific order of notification for your Observers.
* Java has several implementations of the Observer Pattern, including the general purpose java.util.Observable.
* Watch out for issues with the java.util.Observable implementation.
* Don't be afraid to create your own Observable implementation if needed
* Swing makes heavy use of the Observer Pattern. as do many GUI frameworks.
* You'll also find the pattern in many other places, including JavaBeans and RMI
本指南详细阐述基于Python编程语言结合OpenCV计算机视觉库构建实时眼部状态分析系统的技术流程。该系统能够准确识别眼部区域,并对眨眼动作与持续闭眼状态进行判别。OpenCV作为功能强大的图像处理工具库,配合Python简洁的语法特性与丰富的第三方模块支持,为开发此类视觉应用提供了理想环境。 在环境配置阶段,除基础Python运行环境外,还需安装OpenCV核心模块与dlib机器学习库。dlib库内置的HOG(方向梯度直方图)特征检测算法在面部特征定位方面表现卓越。 技术实现包含以下关键环节: - 面部区域检测:采用预训练的Haar级联分类器或HOG特征检测器完成初始人脸定位,为后续眼部分析建立基础坐标系 - 眼部精确定位:基于已识别的人脸区域,运用dlib提供的面部特征点预测模型准确标定双眼位置坐标 - 眼睑轮廓分析:通过OpenCV的轮廓提取算法精确勾勒眼睑边缘形态,为状态判别提供几何特征依据 - 眨眼动作识别:通过连续帧序列分析眼睑开合度变化,建立动态阈值模型判断瞬时闭合动作 - 持续闭眼检测:设定更严格的状态持续时间与闭合程度双重标准,准确识别长时间闭眼行为 - 实时处理架构:构建视频流处理管线,通过帧捕获、特征分析、状态判断的循环流程实现实时监控 完整的技术文档应包含模块化代码实现、依赖库安装指引、参数调优指南及常见问题解决方案。示例代码需具备完整的错误处理机制与性能优化建议,涵盖图像预处理、光照补偿等实际应用中的关键技术点。 掌握该技术体系不仅有助于深入理解计算机视觉原理,更为疲劳驾驶预警、医疗监护等实际应用场景提供了可靠的技术基础。后续优化方向可包括多模态特征融合、深度学习模型集成等进阶研究领域。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
本项目是一个基于STM32的人脸识别系统,利用OPENCV库进行图像处理,采用QT作为图形界面开发。该系统具备人脸采集、图片训练、数据库管理及人脸识别等功能,能够长时间稳定运行,并提供了统一的接口以便进行二次开发。 功能特点 人脸采集:系统能够从视频图像中采集人脸数据。 图片训练:通过提取人脸特征进行训练,提高识别准确性。 数据库管理:管理人脸数据,便于后续的识别和处理。 人脸识别:实现对人脸的检测与识别,适用于多种应用场景。 技术原理 本系统采用基于OPENCV的级联分类检测器,通过视频图像提取人脸特征进行训练。主要技术包括: 光线补偿技术:对图像进行补光处理,提高图像质量。 高斯平滑技术:消除图像噪声,提升图像清晰度。 二值化技术:采用局部阈值进行二值化处理,便于后续的人脸定位和特征提取。 应用场景 人脸识别技术在图像处理与视频检索、视频监控、视频显示等方面具有广泛的应用。本系统适用于以下场景: 安全监控:在公共场所进行人脸识别,提高安全监控效率。 身份验证:用于门禁系统、考勤系统等身份验证场景。 智能交互:在智能家居、智能终端等设备中实现人脸识别交互。 开发环境 硬件平台:STM32微控制器 软件平台:OPENCV库、QT图形界面开发工具 使用说明 环境搭建:确保STM32开发环境及OPENCV、QT库已正确安装。 代码编译:按照提供的Makefile文件进行代码编译。 系统运行:将编译后的程序烧录到STM32开发板,启动系统。 功能测试:通过QT界面进行人脸采集、训练和识别功能测试。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值