opencv 将较小的图片放在较大的副本中不起作用
opencv putting smaller picture in larger copyTo not working
我正在尝试将较小的图片复制到较大的框架上。但我无法让它工作。它编译得很好,但没有显示任何内容。我的目标是将识别出的面复制到较大的原始框架上。
//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
(大帧)的大小与subview
(小帧)的大小不同,因此copyTo
方法将原始帧重新分配给subview
尺寸。要将小帧复制到大帧,您需要定义掩码并将其发送到copyTO
以仅复制该部分(小帧),或者修改subview
因为它是原始帧数据矩阵的一部分。
原因可能是源图像和目标图像的像素格式不相等。
例如,创建为cv::Mat(w , h, CV_8UC3 )
和小图像的大图像,具有像素格式CV_8UC4
在我的情况下不起作用。 复制只需创建一个新图像,而不是写入 ROI。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- C++ 为什么默认副本不起作用?
- ubuntu Linux 中的数组副本实际上不起作用
- opencv 将较小的图片放在较大的副本中不起作用
- 复制构造函数不起作用,无法修改副本