關於我自己

我的相片
累計超過15年的工作經驗,包括10年的設備製造業經驗,超過6年的光電零組件製造業經驗;10年的海外工作經驗,其中至今有5年以上的派駐經驗。 1.專注AOI檢測於10年以上(從光機設計、圖像分析、設備挑選、處理速度) 2.機器學習推論-onnx整合傳統演算法從瑕疵抓取、分析、分類 3.遷移式機器學習模式(工業應用、醫療應用) 4.整合:Python推論引擎、C++運算能力、C#友善介面 彈性使用 5.擅長利用專家模型推進專案,並熟悉使用OpenVINO、TensorRT、ONNXRUNTIME框架進行有效的實作與測試。

2011年10月9日 星期日

HoughCircles

http://rockyhotshow.blogspot.com/

HoughCircles

利用 Hough 變換在灰度圖像中找圓
CvSeq* cvHoughCircles( CvArr* image, void* circle_storage,
                       int method, double dp, double min_dist,
                       double param1=100, double param2=100,
                       int min_radius=0, int max_radius=0 );
image
輸入 8-比特、單通道灰度圖像.
circle_storage
檢測到的圓存儲倉. 可以是記憶體存儲倉 (此種情況下,一個線段序列在存儲倉中被創建,並且由函數返回)或者是包含圓參數的特殊類型的具有單行/單列的CV_32FC3型矩陣(CvMat*). 矩陣頭為函數所修改,使得它的 cols/rows 將包含一組檢測到的圓。如果 circle_storage 是矩陣,而實際圓的數目超過矩陣尺寸,那麼最大可能數目的圓被返回
. 每個圓由三個浮點數表示:圓心坐標(x,y)和半徑.
method
Hough 變換方式,目前只支持CV_HOUGH_GRADIENT, which is basically 21HT, described in [Yuen03].
dp
累加器圖像的解析度。這個參數允許創建一個比輸入圖像解析度低的累加器。(這樣做是因為有理由認為圖像中存在的圓會自然降低到與圖像寬高相同數量的範疇)。如果dp設置為1,則解析度是相同的;如果設置為更大的值(比如2),累加器的解析度受此影響會變小(此情況下為一半)。dp的值不能比1小。
Resolution of the accumulator used to detect centers of the circles. For example, if it is 1, the accumulator will have the same resolution as the input image, if it is 2 - accumulator will have twice smaller width and height, etc.
min_dist
該參數是讓演算法能明顯區分的兩個不同圓之間的最小距離。
Minimum distance between centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed.
param1
用於Canny的邊緣閥值上限,下限被置為上限的一半。
The first method-specific parameter. In case of CV_HOUGH_GRADIENT it is the higher threshold of the two passed to Canny edge detector (the lower one will be twice smaller).
param2
累加器的閥值。
The second method-specific parameter. In case of CV_HOUGH_GRADIENT it is accumulator threshold at the center detection stage. The smaller it is, the more false circles may be detected. Circles, corresponding to the larger accumulator values, will be returned first.
min_radius
最小圓半徑。
Minimal radius of the circles to search for.
max_radius
最大圓半徑。
Maximal radius of the circles to search for. By default the maximal radius is set to max(image_width, image_height).
The function cvHoughCircles finds circles in grayscale image using some modification of Hough transform.
Example. Detecting circles with Hough transform.
#include 
#include 
#include 

int main(int argc, char** argv)
{
    IplImage* img;
    if( argc == 2 && (img=cvLoadImage(argv[1], 1))!= 0)
    {
        IplImage* gray = cvCreateImage( cvGetSize(img), 8, 1 );
        CvMemStorage* storage = cvCreateMemStorage(0);
        cvCvtColor( img, gray, CV_BGR2GRAY );
        cvSmooth( gray, gray, CV_GAUSSIAN, 9, 9 ); // smooth it, otherwise a lot of false circles may be detected
        CvSeq* circles = cvHoughCircles( gray, storage, CV_HOUGH_GRADIENT, 2, gray->height/4, 200, 100 );
        int i;
        for( i = 0; i < circles->total; i++ )
        {
             float* p = (float*)cvGetSeqElem( circles, i );
             cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), 3, CV_RGB(0,255,0), -1, 8, 0 );
             cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(255,0,0), 3, 8, 0 );
        }
        cvNamedWindow( "circles", 1 );
        cvShowImage( "circles", img );
    }
    return 0;
}

2011年10月7日 星期五

[轉貼]圖像處理-Hough線變換和圓變換

http://blog.csdn.net/hustspy1990/article/details/6226374

1. Hough線變換

  1. //Hough線變換  
  2. #include "cv.h"  
  3. #include "highgui.h"  
  4. int main()   
  5. {  
  6.     // TODO: Add your command handler code here  
  7.     IplImage* pImage= NULL;// 聲明IplImage 變量  
  8.     IplImage* pImg8u= NULL;// 聲明IplImage 變量,用於圖像格式轉換  
  9.     IplImage* pImgCanny= NULL;// 聲明IplImage 變量,用於灰度圖像Canny變換  
  10.     CvMemStorage* storage = NULL;// 聲明storage 變量,用於存儲檢測到的線段  
  11.     CvSeq* lines = NULL;   //聲明lines變量,用於存儲直線的輪廓  
  12.       
  13.     //讀入圖像  
  14.     pImage=cvLoadImage("Airplane.jpg", -1);  
  15.     //建立和原始圖像一樣圖像內存區,圖像元素的位深度設為IPL_DEPTH_8U   
  16.     //即無符號8位整型  
  17.     pImg8u = cvCreateImage(cvGetSize(pImage),IPL_DEPTH_8U, 1);  
  18.     pImgCanny = cvCreateImage(cvGetSize(pImage),IPL_DEPTH_8U, 1);  
  19.     //將彩色圖像轉換為灰度圖像  
  20.     cvCvtColor(pImage, pImg8u, CV_BGR2GRAY);  
  21.     //創建內存空間  
  22.     storage = cvCreateMemStorage(0);  
  23.    
  24.     //利用Canny變換找出圖像邊緣  
  25.     cvCanny( pImg8u, pImgCanny, 50, 500, 3 );  
  26.     //Hough線變換  
  27.     lines = cvHoughLines2( pImgCanny, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 80, 30, 10 );  
  28.       
  29.     //在原圖上畫紅直線  
  30.     int i;  
  31.     for( i = 0; i < lines->total; i++ )  
  32.     {  
  33.         CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);  
  34.         cvLine( pImage, line[0], line[1], CV_RGB(255,0,0), 3, 8 );  
  35.     }  
  36.     //創建窗口,顯示圖像  
  37.     cvNamedWindow( "Hough Line Transform", 1 );  
  38.     cvShowImage( "Hough Line Transform", pImage);  
  39.     //等待按鍵  
  40.     cvWaitKey(0);   
  41.     //銷毀窗口  
  42.     cvDestroyWindow( " Hough Line Transform " );      
  43.     //將程序開始定義的變量釋放  
  44.     cvReleaseImage( & pImage);    
  45.     cvReleaseImage( & pImgCanny);  
  46.     cvReleaseImage( & pImg8u);    
  47.      
  48.       
  49. }  
測試

原圖


直線偵測



2. Hough圓變換

  1. //Hough圓變換  
  2. #include "cv.h"  
  3. #include "highgui.h"  
  4. int main()  
  5. {  
  6.     // TODO: Add your command handler code here  
  7.     IplImage* pImage= NULL;// 聲明IplImage 變量  
  8.     IplImage* pImg8u= NULL;// 聲明IplImage 變量,用於圖像格式轉換  
  9.     CvMemStorage* storage = NULL;// 聲明storage 變量,用於存儲檢測到的線段  
  10.     CvSeq* circles = NULL;  
  11.       
  12.     //讀入圖像  
  13.     pImage=cvLoadImage("Airplane.jpg", -1);  
  14.     //建立和原始圖像一樣圖像內存區,圖像元素的位深度設為IPL_DEPTH_8U   
  15.     //即無符號8位整型  
  16.     pImg8u = cvCreateImage(cvGetSize(pImage),IPL_DEPTH_8U, 1);  
  17.     //轉換成灰度圖像  
  18.     if(pImage->nChannels != 1)  
  19.          cvCvtColor( pImage, pImg8u, CV_BGR2GRAY );  
  20.     else  
  21.          cvCopy(pImage, pImg8u);  
  22.     //平滑化  
  23.     cvSmooth( pImg8u, pImg8u, CV_GAUSSIAN, 7, 7 );  
  24.     //創建內存空間  
  25.     storage = cvCreateMemStorage(0);  
  26.     //Hough圓變換  
  27.     circles = cvHoughCircles( pImg8u, storage, CV_HOUGH_GRADIENT, 1, pImg8u->height/4, 250, 55 );  
  28.     // 畫出識別出的圓  
  29.     int i;  
  30.     for( i = 0; i < circles->total; i++ )  
  31.     {  
  32.           float* p = (float*)cvGetSeqElem( circles, i );  
  33.           cvCircle(pImage, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(255,0,0), 3, 8, 0 );  
  34.     }  
  35.     //創建窗口,顯示圖像  
  36.     cvNamedWindow( "Hough Circle Transform", 1 );  
  37.     cvShowImage( "Hough Circle Transform", pImage);  
  38.     //等待按鍵  
  39.     cvWaitKey(0);   
  40.     //銷毀窗口  
  41.     cvDestroyWindow( " Hough Circle Transform " );    
  42.     //將程序開始定義的變量釋放  
  43.     cvReleaseImage( & pImage);    
  44.     cvReleaseImage( & pImg8u);    
  45.       
  46.       
  47. }  
測試

原圖


圓偵測