OpenCV实现乱序碎片复原_第1页
OpenCV实现乱序碎片复原_第2页
OpenCV实现乱序碎片复原_第3页
OpenCV实现乱序碎片复原_第4页
OpenCV实现乱序碎片复原_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第OpenCV实现乱序碎片复原vectorvectorMatresection_LR=edge_resection_LR(fragments);//保存每张碎片的左右边缘

alignment_and_splicing_LR(fragments,resection_LR);//对每张碎片的左右边缘相互对比拼接

vectorMatfragments_LR=fragments_LR_Imread("res/fragments_LR/");//读取左右拼接好的碎片

vectorvectorMatresection_TB=edge_resection_TB(fragments_LR);//保存拼接好的左右碎片的上下边缘

alignment_and_splicing_TB(fragments_LR,resection_TB);//对左右拼接好的碎片的上下边缘相互对比拼接

Matresult=imread("res/result/0.jpg");

imshow("Restorationmap",result);//展示结果

waitKey(0);

return0;

//读取碎片

vectorMatfragments_Imread(stringfiles_name){

vectorstringfiles;

glob(std::move(files_name),files);

vectorMatfragments;

for(autofile:files){

fragments.push_back(imread(file));

returnfragments;

vectorMatfragments_LR_Imread(stringfiles_name){

vectorstringfiles;

glob(std::move(files_name),files);

vectorMatfragments_LR;

for(autofile:files){

fragments_LR.push_back(imread(file));

returnfragments_LR;

//保存每张碎片的左右边缘

vectorvectorMatedge_resection_LR(constvectorMatfragments){

vectorvectorMatresection_LR(fragments.size(),vectorMat(2));

for(inti=0;ifragments.size();i++){

for(intj=0;jj++){

switch(j){

case0://第i张碎片的左边;顶点:(0,0)尺寸:(10*第i张碎片的高/行)

resection_LR.at(i).at(j)=fragments.at(i)(Rect(0,0,10,fragments.at(i).rows));

break;

case1://第i张碎片的右边;顶点:(第i张碎片的宽/列-10,0)尺寸:(10*第i张碎片的高/行)

resection_LR.at(i).at(j)=fragments.at(i)(Rect(fragments.at(i).cols-10,0,10,fragments.at(i).rows));

default:

break;

returnresection_LR;

//直方图对比

boolcompare_by_hist(constMatimg1,constMatimg2){

MattmpImg,orgImg;

resize(img1,tmpImg,Size(img1.cols,img1.rows));

resize(img2,orgImg,Size(img2.cols,img2.rows));

//HSV颜色特征模型(色调H,饱和度S,亮度V)

cvtColor(tmpImg,tmpImg,COLOR_BGR2HSV);

cvtColor(orgImg,orgImg,COLOR_BGR2HSV);

//直方图尺寸设置

//一个灰度值可以设定一个bins,256个灰度值就可以设定256个bins

//对应HSV格式,构建二维直方图

//每个维度的直方图灰度值划分为256块进行统计,也可以使用其他值

inthBins=256,sBins=256;

inthistSize[]={hBins,sBins};

//H:0~180,S:0~255,V:0~255

//H色调取值范围

floathRanges[]={0,180};

//S饱和度取值范围

floatsRanges[]={0,255};

constfloat*ranges[]={hRanges,sRanges};

intchannels[]={0,1};//二维直方图

MatNDhist1,hist2;

calcHist(tmpImg,1,channels,Mat(),hist1,2,histSize,ranges,true,false);

normalize(hist1,hist1,0,1,NORM_MINMAX,-1,Mat());

calcHist(orgImg,1,channels,Mat(),hist2,2,histSize,ranges,true,false);

normalize(hist2,hist2,0,1,NORM_MINMAX,-1,Mat());

doublesimilarityValue=compareHist(hist1,hist2,CV_COMP_CORREL);

//cout"相似度:"similarityValueendl;

returnsimilarityValue=0.95;

//左右拼接

voidpicture_stitching_LR(constMatimg1,constMatimg2){

Matresult;

hconcat(img1,img2,result);

imwrite("res/fragments_LR/"+to_string(n)+".jpg",result);

n++;

//对每张碎片的左右边缘相互对比拼接

voidalignment_and_splicing_LR(constvectorMatfragments,constvectorvectorMatresection_LR){

for(inti=0;ifragments.size()-1;i++){//第i张碎片

for(intj=0;jj++){//第i张碎片的第j条边

for(intk=i;kfragments.size()-1;k++){//第i张碎片的第j条边与第i张以后碎片的左右边缘对比

for(intl=0;ll++){

if(compare_by_hist(resection_LR.at(i).at(j),resection_LR.at(k+1).at(l))){

if(jl){//当jl时被对比的边缘应该在对比右边

picture_stitching_LR(fragments.at(i),fragments.at(k+1));

}elseif(jl){//当jl时被对比的边缘应该在对比右边

picture_stitching_LR(fragments.at(k+1),fragments.at(i));

//上下拼接

voidpicture_stitching_TB(constMatimg1,constMatimg2){

Matresult;

vconcat(img1,img2,result);

imwrite("res/result/"+to_string(m)+".jpg",result);

m++;

//保存左右拼接好的碎片的上下边缘

vectorvectorMatedge_resection_TB(constvectorMatfragments_LR){

vectorvectorMatresection_TB(fragments_LR.size(),vectorMat(2));

for(inti=0;ifragments_LR.size();i++){

for(intj=0;jj++){

switch(j){

case0://第i张碎片的上边缘;顶点:(0,0)尺寸:(第i张碎片的宽/列*10)

resection_TB.at(i).at(j)=fragments_LR.at(i)(Rect(0,0,fragments_LR.at(i).cols,10));

break;

case1://第i张碎片的下边缘;顶点:(0,第i张碎片的高/行-10)尺寸:(第i张碎片的宽/列*10)

resection_TB.at(i).at(j)=fragments_LR.at(i)(Rect(0,fragments_LR.at(i).rows-10,fragments_LR.at(i).cols,10));

default:

break;

returnresection_TB;

//对左右拼接好的碎片进行上下对比拼接

voidalignment_and_splicing_TB(constvectorMatfragments_LR,constvectorvectorMatresection_TB){

for(inti=0;ifragments_LR.size()-1;i++){//第i张碎片

for(intj=0;jj++){//第i张碎片的第j条边

for(intk=i;kfragments_LR.size()-1;k++){//第i张碎片的第j条边与第i张以后碎片的左右边缘对比

for(intl=0;ll++){

if(compare_by_hist(resection_TB.at(i).at(j),resection_TB.at(k+1).at(l))){

//picture_stitching_TB(fragments_LR.at(i),fragments_LR.at(k+1))

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论