OpenCV 6th 識別球體

2021-07-24 23:03:59 字數 3574 閱讀 5343

// streammatchpicture.cpp : 定義控制台應用程式的入口點。

//#include "stdafx.h"

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include "opencv2/core/core.hpp"

#include "opencv2/features2d/features2d.hpp"

#include "opencv2/highgui/highgui.hpp"

#include "opencv2/nonfree/features2d.hpp"

#define npixelvalues 100 //檢測黑白邊界點畫素差閾值

#define ninnerpixelvalue 30 //檢測球心周圍點畫素差閾值

using

namespace cv;

using

namespace

std;

static cvmemstorage* storage = 0;

static

int nfeaturepointx = 0;//頂點x座標

static

int nfeaturepointy = 0;//頂點y座標

static

int nbottomfeaturepointy = 0;//底部端點y座標

static

bool bfeaturetoppoint = false;//球體頂點,底部端點匹配成功

void videoframedrawcircle(iplimage* pframe, iplimage* imgsrc);

void searchforbottompoint(iplimage* pframe, iplimage* pbkimg, int nheight, int nwidth, bool bfeaturebottompoint);

int main(int argc, char** argv)

storage = cvcreatememstorage(0);//建立乙個記憶體儲存器

sleep(1000);//開啟攝像頭之後需要等待1s

for (;;)

pframe->origin = 1;

nfrmnum++;

if (nfrmnum == 1)

else

if (cvwaitkey(1) == 27)//check out never use ese key

break;

}cvreleaseimage(&pbkimg);

cvreleaseimage(&pframe);

cvreleasecapture(&pcapture);

return0;}

void videoframedrawcircle(iplimage* pframe, iplimage* pbkimg)

mat lastframe(pframe);

if (!lastframe.data)

cvclearmemstorage(storage);

int nwidth = pbkimg->width;

int nheight = pbkimg->height;

nfeaturepointx = 0;

nfeaturepointy = 0;

nbottomfeaturepointy = 0;

double r1 = 0.000000, g1 = 0.000000, b1 = 0.000000;

double r2 = 0.000000, g2 = 0.000000, b2 = 0.000000;

double r3 = 0.000000, g3 = 0.000000, b3 = 0.000000;

bfeaturetoppoint = false;

bool bfeaturebottompoint = false;//bool:find bottom featurepoint

for (int i = 0; i//檢測圓形的頂點座標位置

nfeaturepointx = j;

nfeaturepointy = i + 1;

searchforbottompoint(pframe, pbkimg, nheight, nwidth, false);//檢測球體的底部頂點,左右邊界頂點:畫球體投影輪廓

}else

}else}}

else

}}void searchforbottompoint(iplimage* pframe, iplimage* pbkimg, int nheight, int nwidth, bool bfeaturebottompoint = false)//畫球體輪廓:檢測球底部頂點

else

//否則,縮小遞迴變數單位值,迴圈初始值為上一次最後y座標值

bexist = true;//遍歷一邊,存在特徵點

break;}}

else

//影象高度越界:

else

if (bexist && nstep == 2)

break;}}

if (!bexist)//確定了頂部特徵點的情況下,如果一輪下來沒有區別的畫素值發現:則終點是底部點

}//draw circle

int pointy = (int)((nfeaturepointy + nbottomfeaturepointy) / 2);

int radius = (int)((nbottomfeaturepointy - nfeaturepointy) / 2);

cvzero(pbkimg);

if (radius < 0)

return;

if (nfeaturepointx 2)//如果球體與邊界左右相交,不做處理,退出

return;

if (nfeaturepointx + radius + 2>(nwidth - 2))

return;

bfeaturetoppoint = true;//頂點和底部端點匹配成功,符合球體規則

cvcircle(pbkimg, cvpoint(nfeaturepointx, pointy), radius, cv_rgb(0, 255, 255), 1, 8, 0);//畫圓

cstring str1;

str1.format(_t("circle point(%d,%d) radius = %d successful \n"), nfeaturepointx, pointy, radius);

outputdebugstring(str1);

cvflip(pbkimg, null, 0);

cvshowimage("circle", pbkimg);

}

【問題】:不穩定,太近不準確。

opencv中cvcircle的使用方法

python實現opencv學習二十四 識別驗證碼

驗證碼識別前期準備 2.安裝pytesseract pip install pytesseract 3.之前pil,pillow已經裝過,如果沒有安裝pil的 請看這裡 4.我的環境 python2.7 opencv3.4 如下 coding gbk import cv2 as cv import ...

python中使用Opencv進行人臉識別

python中使用opencv進行人臉識別 cv2.imshow無法顯示影象 在執行cv2.imshow後,需要使用cv2.waitkey來保持視窗的顯示。python opencv影象標註矩形框bounding box 用 opencv 標註 bounding box 主要用到下面兩個工具 cv2...

基於Opencv自帶BP網路的車標簡易識別

位址如下 記得把這幾點描述好咯 實現過程 專案檔案結構截圖 演示效果 先將資料集手動劃分成訓練集和測試集,並分好類,比如第一類就放在資料夾名為0的資料夾下,第二類就是1,如此類推。當前程式只能處理10類以下車標,因為當前程式邏輯不支援10以上的數字識別 具體可以仔細看下 所有訓練集的放在train資...