OpenCV 如何检测网络摄像头并比较本地文件以匹配面部

发布于 2024-11-09 00:16:53 字数 923 浏览 0 评论 0原文

突出显示的代码演示了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事与诗 2024-11-16 00:16:53

捕获视频帧很简单,只需按照此示例即可。重要的部分是:

IplImage *img = cvLoadImage( argv[1], CV_LOAD_IMAGE_COLOR );
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
while ( 1 ) {
    IplImage* frame = cvQueryFrame( capture );
    //match(img,frame);
}
cvReleaseCapture( &capture );

第二部分可能要困难得多,取决于您到底想做什么。如果您想简单地比较图像,可以使用 cvNorm。如果您想要人脸检测或人脸识别,您确实需要知道自己在做什么。

Capturing a video frame is simple just follow this example. The essential part is:

IplImage *img = cvLoadImage( argv[1], CV_LOAD_IMAGE_COLOR );
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
while ( 1 ) {
    IplImage* frame = cvQueryFrame( capture );
    //match(img,frame);
}
cvReleaseCapture( &capture );

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.

一梦浮鱼 2024-11-16 00:16:53

这就是我获取网络摄像头提要的方式...(代码是 Python 语言,但很容易翻译)

# create capture device
device = 0 # assume we want first device
capture = cv.CreateCameraCapture(0)
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, 640)
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 480)    

# check if capture device is OK
if not capture:
    print "Error opening capture device"
    sys.exit(1)

# capture the current frame
frame = cv.QueryFrame(capture)

if frame is None:
    break
    # mirror

cv.Flip(frame, None, 1)   

#Do face detection here

我认为尝试将单个文件中的脸部与实时视频流进行匹配会非常困难。查看 cv.HaarDetectObjects 以获得一些很酷的特征检测算法。

This is how I get a webcam feed... (the code is in Python but is easily translated)

# create capture device
device = 0 # assume we want first device
capture = cv.CreateCameraCapture(0)
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, 640)
cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 480)    

# check if capture device is OK
if not capture:
    print "Error opening capture device"
    sys.exit(1)

# capture the current frame
frame = cv.QueryFrame(capture)

if frame is None:
    break
    # mirror

cv.Flip(frame, None, 1)   

#Do face detection here

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文