gpt4 book ai didi

c++ - opencv 将较小的图片放入较大的拷贝中无法正常工作

转载 作者:行者123 更新时间:2023-11-28 05:37:59 25 4
gpt4 key购买 nike

我正在尝试将较小的图片复制到较大的框架上。但我无法让它工作。它编译得很好,但没有显示任何内容。我的目标是将识别出的人脸复制到更大的原始框架上。

//NEW
Mat face_resized;
//NEW
for(int i = 0; i < faces.size(); i++) {

// Process face by face:
Rect face_i = faces[i];
// Crop the face from the image. So simple with OpenCV C++:
Mat face = gray(face_i);

// Resizing the face is necessary for Eigenfaces and Fisherfaces. You can easily
// verify this, by reading through the face recognition tutorial coming with OpenCV.
// Resizing IS NOT NEEDED for Local Binary Patterns Histograms, so preparing the
// input data really depends on the algorithm used.
//
// I strongly encourage you to play around with the algorithms. See which work best
// in your scenario, LBPH should always be a contender for robust face recognition.
//
// Since I am showing the Fisherfaces algorithm here, I also show how to resize the
// face you have just found:
//NEW
face_resized=images[images.size()-1];
//Mat face_resized=images[images.size()-1];
//NEW

cv::resize(face, face_resized, Size(im_width, im_height), 1.0, 1.0, INTER_CUBIC);
//model->setLabelsInfo(labelsInfo);
// Now perform the prediction, see how easy that is:
int prediction = model->predict(face_resized);
double confidence = 0.0;
model->predict(face_resized,prediction,confidence);

// And finally write all we've found out to the original image!
// First of all draw a green rectangle around the detected face:
rectangle(original, face_i, CV_RGB(0, 255,0), 1);

和:

//NEW
cv::Rect roi = cv::Rect(50,50, face_resized.cols, face_resized.rows);
cv::Mat subview = original(roi);
subview.copyTo(original);
//NEW
while(tmp!=0) {
putText(original, tmp->name, Point(10,y),FONT_HERSHEY_PLAIN,1.0,CV_RGB(100,100,0),1.0);
y+=10;
tmp=tmp->next;}
}

imshow("face_recognizer", original);

(我只复制了相关的部分,如果需要可以再发)

最佳答案

CopyTo 方法将矩阵数据复制到另一个矩阵。在复制数据之前,该方法调用 m.create(this->size(), this->type()) 以便在需要时重新分配目标矩阵。即 copyto 适用于相同大小的矩阵。从您的示例代码中,

cv::Mat subview = original(roi);
subview.copyTo(original);

我看到您正在从 original 获取 roi(subview) 并再次将其复制到 original。作为 original(big frame) 与 subview(small) 大小不同,原始框架在 copyTo 方法中重新分配到 subview 大小.要将小框架复制到大框架,您需要定义掩码并将其发送到 copyTO 以仅复制该部分(小框架)或修改 subview原始帧数据矩阵的一部分。

关于c++ - opencv 将较小的图片放入较大的拷贝中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37783774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com