OpenCV:相对于参考的Shift / Align面部图像(图像注册) [英] OpenCV: Shift/Align face image relative to reference Image (Image Registration)

查看:128
本文介绍了OpenCV:相对于参考的Shift / Align面部图像(图像注册)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OpenCV2的新人,正在处理情绪识别的项目,并希望将面部图像与参考面部图像相关联。我想在移动到旋转之前获得图像转换工作。当前想法是在x和y坐标上的有限范围内运行搜索,并使用平方差的和作为误差度量来选择用于对准图像的最佳x / y参数。我使用OpenCV face_cascade函数来检测面部图像,所有图像都调整为固定(128x128)。问题:我需要修改Mat图像的哪些参数以在x和y轴上沿正/负方向移动图像?我相信setImageROI不再支持Mat数据类型?我有两个面孔的ROI,但我不确定如何使用它们。

I am new to OpenCV2 and working on a project in emotion recognition and would like to align a facial image in relation to a reference facial image. I would like to get the image translation working before moving to rotation. Current idea is to run a search within a limited range on both x and y coordinates and use the sum of squared differences as error metric to select the optimal x/y parameters to align the image. I'm using the OpenCV face_cascade function to detect the face images, all images are resized to a fixed (128x128). Question: Which parameters of the Mat image do I need to modify to shift the image in a positive/negative direction on both x and y axis? I believe setImageROI is no longer supported by Mat datatypes? I have the ROIs for both faces available however I am unsure how to use them.

void alignImage(vector<Rect> faceROIstore, vector<Mat> faceIMGstore)
{
  Mat refimg = faceIMGstore[1]; //reference image
  Mat dispimg = faceIMGstore[52]; // "displaced" version of reference image
  //Rect refROI = faceROIstore[1]; //Bounding box for face in reference image
  //Rect dispROI = faceROIstore[52]; //Bounding box for face in displaced image
  Mat aligned;

  matchTemplate(dispimg, refimg, aligned, CV_TM_SQDIFF_NORMED);
  imshow("Aligned image", aligned);
}

这种方法的想法是基于 Richard Szeliski的图像对齐教程使用OpenCV 2.4在Windows上工作。任何建议都非常感谢。

The idea for this approach is based on Image Alignment Tutorial by Richard Szeliski Working on Windows with OpenCV 2.4. Any suggestions are much appreciated.

推荐答案

cv :: Mat 投资回报率。 (但不支持COI - 兴趣频道。)

cv::Mat does support ROI. (But it does not support COI - channel-of-interest.)

要应用ROI,您可以使用 operator()或特殊建构函式:

To apply ROI you can use operator() or special constructor:

Mat refimgROI  = faceIMGstore[1](faceROIstore[1]); //reference image ROI
Mat dispimgROI(faceIMGstore[52], faceROIstore[52]); // "displaced" version of reference image ROI

为了找到位移图像中的最佳位置可以使用 matchTemplate 功能。

And to find the best position inside a displaced image you can utilize matchTemplate function.

根据您的意见,我可以建议下面的代码,找到第二(位移)补丁附近的参考补丁的最佳位置:

Based on your comments I can suggest the following code which will find the best position of reference patch nearby the second (displaced) patch:

Mat ref = faceIMGstore[1](faceROIstore[1]);
Mat disp = faceIMGstore[52](faceROIstore[52]);

disp = disp.adjustROI(5,5,5,5); //allow 5 pixel max adjustment in any direction
if(disp.cols < ref.cols || disp.rows < ref.rows)
    return 0;
Mat map;
cv::matchTemplate( disp, ref, map, CV_TM_SQDIFF_NORMED );

Point  minLoc;
cv::minMaxLoc( map, 0, &minLoc );

Mat adjusted = disp(Rect(minLoc.x, minLoc.y, ref.cols, ref.rows));

这篇关于OpenCV:相对于参考的Shift / Align面部图像(图像注册)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆