91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 7KB
    文件類型: .cpp
    金幣: 1
    下載: 1 次
    發布日期: 2021-06-17
  • 語言: C/C++
  • 標簽: opencv2??矩形檢測??

資源簡介

(1)實現了矩形的檢測(2)此代碼是針對圖片中的矩形進行的(3)此代碼實現了一個文件夾里的圖片的批量處理

資源截圖

代碼片段和文件信息

#include
#include
#include
#include
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?se.h>




using?namespace?std;
using?namespace?cv;

string?imgpath?=?“E:\\大貝殼\\C++\\Lab\\Lab\\pic\\“;
string?savepath?=?“E:\\大貝殼\\C++\\Lab\\Lab\\Rect3(15)s\\“;


Mat?back?result;
int?thresh?=?50;
IplImage*?img?=?NULL;
IplImage*?img0?=?NULL;
CvMemStorage*?storage?=?NULL;

string?imageName;




vector?getfiles(const?string&?dir?const?string&?extension?bool?withpath){
vector?filenames;
string?p;
_tfinddata64_t?file;
intptr_t?lf;
if?((lf?=?_tfindfirst64(p.assign(dir).append(“\\*.“).append(extension).c_str()?&file))?==?-1l)
cout?< else
{
do
{
if?(withpath){
filenames.push_back(p.assign(dir).append(“\\“).append(file.name));

}
else{
filenames.push_back(file.name);
}
}?while?(_tfindnext64(lf?&file)?==?0);
}
_findclose(lf);

sort(filenames.begin()?filenames.end());
return?filenames;
}





//angle函數用來返回(兩個向量之間找到角度的余弦值)
double?angle(CvPoint*?pt1?CvPoint*?pt2?CvPoint*?pt0)
{
double?dx1?=?pt1->x?-?pt0->x;
double?dy1?=?pt1->y?-?pt0->y;
double?dx2?=?pt2->x?-?pt0->x;
double?dy2?=?pt2->y?-?pt0->y;
return?(dx1*dx2?+?dy1*dy2)?/?sqrt((dx1*dx1?+?dy1*dy1)*(dx2*dx2?+?dy2*dy2)?+?1e-10);
}

//?返回圖像中找到的所有輪廓序列,并且序列存儲在內存存儲器中

CvSeq*?findSquares4(IplImage*?img?CvMemStorage*?storage)
{
CvSeq*?contours;
int?i?c?l?N?=?11;
//矩形框的大小
CvSize?sz?=?cvSize(img->width?&?-2?img->height?&?-2);

IplImage*?timg?=?cvCloneImage(img);
IplImage*?gray?=?cvCreateImage(sz?8?1);
IplImage*?pyr?=?cvCreateImage(cvSize(sz.width?/?2?sz.height?/?2)?8?3);
IplImage*?tgray;
CvSeq*?result;
double?s?t;

//?創建一個空序列用于存儲輪廓角點
//CvSeq本身就是一個可增長的序列,不是固定的序列
CvSeq*?squares?=?cvCreateSeq(0?sizeof(CvSeq)?sizeof(CvPoint)?storage);


//實例說明:cvSetImageROI(img1cvRect(100100356156)),
//(100100) 表示ROI區域的左上角坐標,356156分別表示ROI區域的長寬。
cvSetImageROI(timg?cvRect(0?0?sz.width?sz.height));
//?過濾噪音
//圖像金字塔,放大,縮小
cvPyrDown(timg?pyr?7);
cvPyrUp(pyr?timg?7);
tgray?=?cvCreateImage(sz?8?1);

//?紅綠藍3色分別嘗試提取
for?(c?=?0;?c? {
//?提取?the?c-th?color?plane
//cvSetImageCOI(IplImage*?image?int?coi):(A?pointer?to?the?image?headerThe?channel?of?interest.)
cvSetImageCOI(timg?c?+?1);
cvCopy(timg?tgray?0);

//?嘗試各種閾值提取得到的(N=11)
for?(l?=?0;?l? {
//?apply?Canny.?Take?the?upper?threshold?from?slider
//?Canny?helps?to?catch?squares?with?gradient?shading??
if?(l?==?0)
{
cvCanny(tgray?gray?0?thresh?5);
//使用任意結構元素膨脹圖像
cvDilate(gray?gray?0?1);
}
else
{
//?apply?threshold?if?l!=0:
cvThreshold(tgray?gray?(l?+?1)?*?255?/?N?255?CV_THRESH_BINA

評論

共有 條評論