久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

OpenCV點目標檢測未找到所有目標,并且找到的圓

OpenCV dot target detection not finding all targets, and found circles are offset(OpenCV點目標檢測未找到所有目標,并且找到的圓圈偏移)
本文介紹了OpenCV點目標檢測未找到所有目標,并且找到的圓圈偏移的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試檢測黑/白點目標的中心,如圖所示.我嘗試使用 cv2.HoughCircles 方法,但 1,只能檢測 2 到 3 個目標,2,當我將找到的圓圈重新繪制到圖像上時,它們總是略微偏移.

I'm trying to detect the center of black/white dot targets, like in this picture. I've tried to use the cv2.HoughCircles method but 1, am only able to detect 2 to 3 targets, and 2, when I plot the found circles back onto the image, they're always offset slightly.

我是否使用了錯誤的方法?我應該使用 findContours 還是完全不同的東西?

Am I using the wrong method? Should I be using the findContours or something completely different?

這是我的代碼:

import cv2
from cv2 import cv
import os
import numpy as np

def showme(pic):
    cv2.imshow('window',pic)
    cv2.waitKey()
    cv2.destroyAllWindows()


im=cv2.imread('small_test.jpg')

gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)

#I've tried blur,bw,tr...  all give me poor results.

blur = cv2.GaussianBlur(gray,(3,3),0)
n,bw = cv2.threshold(blur,120,255,cv2.THRESH_BINARY)
tr=cv2.adaptiveThreshold(blur,255,0,1,11,2)

circles = cv2.HoughCircles(gray, cv.CV_HOUGH_GRADIENT, 3, 100, None, 200, 100, 5, 16)

try:
    n = np.shape(circles)
    circles=np.reshape(circles,(n[1],n[2]))
    print circles
    for circle in circles:
        cv2.circle(im,(circle[0],circle[1]),circle[2],(0,0,255))
    showme(im)
except:
    print "no cicles found"

這是我當前的輸出:

推薦答案

播放我在另一篇文章中寫的代碼,我能夠取得稍微好一點的結果:

Playing the code I wrote in another post, I was able to achieve a slightly better result:

一切都與參數有關.始終如此.

您應該嘗試在此程序中調用 3 個重要的函數:cvSmooth()cvCanny()cvHoughCircles().他們每個人都有可能徹底改變結果.

There are 3 important functions that are called in this program that you should experiment with: cvSmooth(), cvCanny(), and cvHoughCircles(). Each of them has the potential to change the result drastically.

這里是 C 代碼:

IplImage* img = NULL;
if ((img = cvLoadImage(argv[1]))== 0)
{
    printf("cvLoadImage failed
");
}

IplImage* gray = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
CvMemStorage* storage = cvCreateMemStorage(0);

cvCvtColor(img, gray, CV_BGR2GRAY);

// This is done so as to prevent a lot of false circles from being detected
cvSmooth(gray, gray, CV_GAUSSIAN, 7, 9);

IplImage* canny = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
IplImage* rgbcanny = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
cvCanny(gray, canny, 40, 240, 3);

CvSeq* circles = cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT, 2, gray->height/8, 120, 10, 2, 25);
cvCvtColor(canny, rgbcanny, CV_GRAY2BGR);

for (size_t i = 0; i < circles->total; i++)
{
     // round the floats to an int
     float* p = (float*)cvGetSeqElem(circles, i);
     cv::Point center(cvRound(p[0]), cvRound(p[1]));
     int radius = cvRound(p[2]);

     // draw the circle center
     cvCircle(rgbcanny, center, 3, CV_RGB(0,255,0), -1, 8, 0 );

     // draw the circle outline
     cvCircle(rgbcanny, center, radius+1, CV_RGB(0,0,255), 2, 8, 0 );

     printf("x: %d y: %d r: %d
",center.x,center.y, radius);
}

cvNamedWindow("circles", 1);
cvShowImage("circles", rgbcanny);

cvSaveImage("out.png", rgbcanny);
cvWaitKey(0);

我相信你有能力將它移植到 Python.

I trust you have the skills to port this to Python.

這篇關于OpenCV點目標檢測未找到所有目標,并且找到的圓圈偏移的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 自拍偷拍亚洲一区 | 在线一区 | 在线āv视频| 一区欧美| 久久久久亚洲国产| 中文字幕乱码一区二区三区 | 久久人人爽人人爽人人片av免费 | 久久tv在线观看 | 欧美精品成人一区二区三区四区 | 黄色毛片在线看 | 日韩国产在线 | 成人精品一区二区三区四区 | av免费网站在线观看 | 国产高清视频一区 | 四色永久| 国产欧美在线 | 精品一区二区在线视频 | 亚洲国产精品第一区二区 | 在线观看免费黄色片 | 日本一区二区三区四区 | 超碰导航 | 狠狠视频| 日本不卡高字幕在线2019 | 国产aa | 一区二区三区四区免费观看 | 国产免费一区二区三区 | 欧美极品在线播放 | 亚洲97 | 亚洲精品小视频在线观看 | 国产午夜久久久 | 久久高潮 | 中文字幕精品一区 | 99精品国产在热久久 | 欧美人妖网站 | 91免费高清视频 | 国产精品a久久久久 | 五月婷婷亚洲 | 18性欧美 | 黄色欧美在线 | 自拍偷拍在线视频 | 久久亚洲欧美日韩精品专区 |