我在C ++中使用带贡献的OpenCV 3.1。尝试重新创建“使用OpenCV学习图像处理pg 152-161”中概述的程序。我逐行复制了代码,但遇到此错误。
//-Create a blender-//S10
Ptr<Blender> blender = Blender::createDefault(blend_type,false);
Size dst_sz = resultRoi(corners, sizes).size();
float blend_width = sqrt(static_cast<float>(dst_sz.area()))* blend_strength / 100.f;
if(blend_width < 1.f){
blender = Blender::createDefault(Blender::NO,false);
}
else if(blend_type == Blender::MULTI_BAND){
MultiBandBlender* mb = dynamic_cast<MultiBandBlender*>(blender.get());
mb->setNumBands(static_cast<int>(ceil(log(blend_width)/log(2.))-1.));
cout << "Multi-band blender, number of bands: " << mb->numBands() << endl;
}
else if(blend_type == Blender::FEATHER){
FeatherBlender* fb = dynamic_cast<FeatherBlender*>(blender.get());
fb->setSharpness(1.f/blend_width);
cout << "Feather blender, sharpness: " << fb->sharpness() << endl;
}
blender->prepare(corners,sizes);
//-Compositing step-//S11
cout << "Composting..." << endl;
t = getTickCount();
Mat img_warped, img_warped_s;
Mat dilated_mask, seam_mask, mask, mask_warped;
for(int img_idx = 0; img_idx < num_images; img_idx++){
cout << "Compositing image #" << indices[img_idx]+1 << endl;
//-Read image and resize it if necessary-//S11.1
full_img = imread(img_names[img_idx]);
if(abs(scale - 1)> 1e-1){
resize(full_img, img, Size(),scale,scale);
}
else{
img = full_img;
}
full_img.release();
Size img_size = img.size();
Mat K;
cameras[img_idx].K().convertTo(K, CV_32F);
//-Warp the current image-//S11.2
warper->warp(img,K,cameras[img_idx].R,INTER_LINEAR,BORDER_REFLECT,img_warped);
//Warp the current image mask
mask.create(img_size, CV_8U);
mask.setTo(Scalar::all(255));
warper->warp(mask,K,cameras[img_idx].R,INTER_NEAREST,BORDER_CONSTANT,mask_warped);
//-Compenstae exposure error step-//S11.3
compensator->apply(img_idx,corners[img_idx],img_warped,mask_warped);
img_warped.convertTo(img_warped, CV_16S);
img_warped.release();
img.release();
mask.release();
dilate(masks_warped[img_idx], dilated_mask, Mat());
resize(dilated_mask, seam_mask, mask_warped.size());
mask_warped = seam_mask & mask_warped;
//-Blending images step-//S11.4
blender->feed(img_warped_s,mask_warped,corners[img_idx]);
}
问题在最后一行说:
错误:(-215)img.type()== CV_16SC3 || img.type()== CV_8UC3在 功能供稿
在img,遮罩和tl中执行blender :: feed函数任务,我认为问题出在img img_warped
变量上,并尝试将其转换为CV_16SC3和CV_8UC3类型,但是没有用。任何帮助表示赞赏。
答案 0 :(得分:0)
如评论中所述,我没有填充img_warped_s
。