在对图像处理时,由于图像中的阴影出现,导致算法无法进行,怎样可以将单幅图像里的阴影消去
1条回答
关注 /*********************************************/ //阴影检测 /*********************************************/ CvPoint downleft,upright; int cnt; int dir[8][2]={-1,-1,-1,0,-1,1,0,1,0,-1,1,1,1,0,1,-1}; #define SHADOW 170 #define Thres_KindNumber 20 bool InRange(CvPoint point,IplImage* pi) { int w=pi->width; int h=pi->height; if(point.x>=0&&point.x<w&&point.y>=0&&point.y<h) { float v[3]; for(i=0;i<3;i++) { v[i]=((uchar*)(pi->imageData + pi->widthStep*point.y))[point.x*3+i]; if(v[i]<=SHADOW) return true; } } return false; } void Dye(IplImage** curimg,CvPoint s) { int i; queue<CvPoint>Q; Q.push(s); for(i=0;i<3;i++) ((uchar*)((*curimg)->imageData + (*curimg)->widthStep*s.y))[s.x*3+i]=SHADOW+10; while(!Q.empty()) { s=Q.front(); Q.pop(); if(s.x<downleft.x) downleft.x=s.x; if(s.y<downleft.y) downleft.y=s.y; if(s.x>upright.x) upright.x=s.x; if(s.y>upright.y) upright.y=s.y; //dye around for(i=0;i<8;i++) { CvPoint now=cvPoint(s.x+dir[i][0],s.y+dir[i][1]); if(InRange(now,*curimg)) { Q.push(now); cnt++; for(i=0;i<3;i++) ((uchar*)((*curimg)->imageData + (*curimg)->widthStep*now.y))[now.x*3+i]=SHADOW+10; } } } } void CCVMFCView::OnShadowDetect() { //detect shadows,find the region with highest pixel value int x,y; srcimg=workImg; for(y=0;y<srcimg->height;y++) for(x=0;x<srcimg->width;x++) { CvPoint curp=cvPoint(x,y); downleft.x=srcimg->width;downleft.y=srcimg->height; upright.x=upright.y=0; cnt=0; if(InRange(curp,srcimg)) Dye(&srcimg,curp); if(cnt>Thres_KindNumber) cvRectangle(workImg , downleft,upright,CV_RGB(0,255,0),1,CV_AA,0); } Invalidate(); }
检测好了以后去除就很方便了
解决 无用评论 打赏 举报
悬赏问题
- ¥50 永磁型步进电机PID算法
- ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
- ¥88 找成都本地经验丰富懂小程序开发的技术大咖
- ¥15 如何处理复杂数据表格的除法运算
- ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
- ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
- ¥200 uniapp长期运行卡死问题解决
- ¥15 latex怎么处理论文引理引用参考文献
- ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
- ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?