OpenCV 如何检测网络摄像头并比较本地文件以匹配面部
突出显示的代码演示了 openCV 框架已加载到我的 C 代码中,并且它呈现了警察的观看效果。这只是为了证明它工作起来非常流畅并且编写的代码非常干净。
目标: 我的网络摄像头已连接到 USB 端口。我想捕获实时网络摄像头图像并从本地文件(/tmp/myface.png)进行匹配,如果实时网络摄像头与本地文件 myface.png 匹配,它将显示文本“警察正在监视”
我的问题修复: 1)我现在如何通过以下代码捕获我的网络摄像头? 2)当网络摄像头被捕获时,我如何加载文件并查找它是否匹配,匹配时它仅显示文本。
#include "cv.h"
#include "highgui.h"
int main()
{
CvPoint pt = cvPoint( 620/4, 440/2 ); // width, height
IplImage* hw = cvCreateImage(cvSize(620, 440), 8,3); // width, height
CvFont font; // cvSet(hw,cvScalar(0,0,0)); // optional
cvInitFont (&font, CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0, 0, 1, CV_AA);
cvPutText (hw, "Police watching", pt, &font, CV_RGB(150, 0, 150));
cvShowImage("Police watching", hw); //cvNamedWindow("Police watching", 0); // optional
cvWaitKey (0);
}
注意:当这个模型起作用时,我将练习它以转换为 JNI java 模型。
The highlighted code demonstrate openCV framework is loaded in my C code and it render Police watching. Which is just to demonstrate it works very smooth and very clean code to write.
Target:
My webCAM is connected in to the USB port. I would like to capture the live webcam image and match from a local file (/tmp/myface.png), if live webcam match with local file myface.png, it will show the text "Police watching"
My Questions to fix:
1) How can i now, capture my webCAM on this following code?
2) When the webCAM is captured, how can i load the file and find if it match, on match it shows that text only.
#include "cv.h"
#include "highgui.h"
int main()
{
CvPoint pt = cvPoint( 620/4, 440/2 ); // width, height
IplImage* hw = cvCreateImage(cvSize(620, 440), 8,3); // width, height
CvFont font; // cvSet(hw,cvScalar(0,0,0)); // optional
cvInitFont (&font, CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0, 0, 1, CV_AA);
cvPutText (hw, "Police watching", pt, &font, CV_RGB(150, 0, 150));
cvShowImage("Police watching", hw); //cvNamedWindow("Police watching", 0); // optional
cvWaitKey (0);
}
Note: When this model will work i will practice this to convert in to JNI java model.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
捕获视频帧很简单,只需按照此示例即可。重要的部分是:
第二部分可能要困难得多,取决于您到底想做什么。如果您想简单地比较图像,可以使用 cvNorm。如果您想要人脸检测或人脸识别,您确实需要知道自己在做什么。
Capturing a video frame is simple just follow this example. The essential part is:
The second part is probably much harder and depends on what exactly are you trying to do. If you want to simply compare images, you can use cvNorm. If you want face detection or face recognition you really need to know what are you doing.
这就是我获取网络摄像头提要的方式...(代码是 Python 语言,但很容易翻译)
我认为尝试将单个文件中的脸部与实时视频流进行匹配会非常困难。查看 cv.HaarDetectObjects 以获得一些很酷的特征检测算法。
This is how I get a webcam feed... (the code is in Python but is easily translated)
I think you'll have an incredibly hard time trying to match a face from a single file to a live video stream. Look into cv.HaarDetectObjects for some cool feature detection algorithms.