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

計算圖像中的彩色點

count colored dots in image(計算圖像中的彩色點)
本文介紹了計算圖像中的彩色點的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

首先,對不起,如果這個話題已經存在(我認為這是一個常見的任務,但找不到任何東西).

關鍵是我有一張圖像,它顯示了不同顏色的不同點.我需要一個腳本來計算有多少個紅點、綠點和黃點.顏色是純紅色(ff0000)、綠色(00ff00)和黃色(ffff00).這使得這更容易,并且形狀定義明確.

我目前的方法是選擇圓形(點)形狀,選擇它們,然后一旦我將所有點都遠離背景圖像,讀取它的顏色來計算它們......

關鍵是我很迷茫.我知道這可以通過 OpenCV 完成,但不知道如何(也找不到任何好的教程).

有什么想法嗎?

解決方案

這是一個基于OpenCV 3.2Python 2.7的示例解決方案.

要計算彩色點,請對每種顏色類型重復以下 4 個步驟.

  1. 應用中值濾波器降低噪音 - cv2.medianBlur().
  2. 應用顏色閾值來分割彩色點 - 使用 cv2.inRange().
  3. 使用

    綠色 - 39 點

    黃色 - 30 點

    請注意,未檢測到右側最后一個小于半圓的黃點.這可能是霍夫圓變換 cv2.HoughCircles() 的限制.因此,如果發生此類問題,您需要決定如何處理.

    這里是示例代碼:

    導入 cv2導入 numpyred = [(0,0,240),(10,10,255)] # 上下綠色 = [(0,240,0),(10,255,10)]黃色 = [(0,240,250),(10,255,255)]dot_colors = [紅、綠、黃]img = cv2.imread('./imagesStackoverflow/count_colored_dots.jpg')# 在閾值處理之前應用中值模糊來平滑圖像blur= cv2.medianBlur(img, 7) # 以 7x7 像素平滑圖像,可能需要稍微調整一下對于 dot_colors 中的下、上:輸出 = img.copy()# 將閾值顏色應用于白色 (255,255, 255),其余應用于黑色 (0,0,0)掩碼 = cv2.inRange(模糊,下,上)circles = cv2.HoughCircles(mask,cv2.HOUGH_GRADIENT,1,20,param1=20,param2=8,最小半徑=0,最大半徑=60)索引 = 0如果 circles 不是 None:# 將圓的 (x, y) 坐標和半徑轉換為整數circles = numpy.round(circles[0, :]).astype("int")# 循環 (x, y) 坐標和圓的半徑對于 (x, y, r) 的圓圈:# 在輸出圖像中畫圓,# 然后畫一個對應圓心的矩形cv2.circle(輸出, (x, y), r, (255, 0, 255), 2)cv2.rectangle(輸出, (x - 5, y - 5), (x + 5, y + 5), (255, 0, 255), -1)索引 = 索引 + 1#print str(index) + ":"+ str(r) + ", (x,y) = "+ str(x) + ', ' + str(y)打印'沒有.檢測到的圓圈數 = {}'.format(index)

    希望對您有所幫助.

    First of all, sorry if this topic already exists (I think this is a common task, but couldn't find anything).

    The point, is that I have an image who shows different dots of different colors. And I need an script to count how many red, green and yellow dots are. The colors are pure red(ff0000), green(00ff00) and yellow(ffff00). Which makes this easier, and the shape is well defined.

    My current approach is to select the round(dot) shape, select them and then once I have all dots away from background image, read its color to count them...

    The point is that I'm so lost with this. I know that this can be done with OpenCV but don't know how (and couldn't find any nice tutorial).

    Any idea?

    解決方案

    Here is a sample solution based on OpenCV 3.2 and Python 2.7.

    To count the colored dots, repeat below 4 steps once per color type.

    1. Apply median filter to reduce noise - cv2.medianBlur().
    2. Apply color threshold to segment the colored dots - use cv2.inRange().
    3. Use Hough Circle Transform to detect the circles - use circles = cv2.HoughCircles(mask,cv2.HOUGH_GRADIENT,...)
    4. Loop through each detected circles to draw its center and a circle around it, and count the numbers of colored dots.

    Sample images of dots detected:

    Red - 10 dots

    Green - 39 dots

    Yellow - 30 dots

    Take note that the last yellow dots at the right side with less than half a circle hasn't been detected. This is likely a limitation of the Hough Circle Transform cv2.HoughCircles(). So you need to decide how to handle this type of issue if it happens.

    Here is the sample code:

    import cv2
    import numpy
    
    red = [(0,0,240),(10,10,255)] # lower and upper 
    green = [(0,240,0),(10,255,10)]
    yellow = [(0,240,250),(10,255,255)]
    dot_colors = [red, green, yellow]
        
    img = cv2.imread('./imagesStackoverflow/count_colored_dots.jpg')   
    # apply medianBlur to smooth image before threshholding
    blur= cv2.medianBlur(img, 7) # smooth image by 7x7 pixels, may need to adjust a bit
    
    for lower, upper in dot_colors:
        output = img.copy()
        # apply threshhold color to white (255,255, 255) and the rest to black(0,0,0)
        mask = cv2.inRange(blur,lower,upper) 
    
        circles = cv2.HoughCircles(mask,cv2.HOUGH_GRADIENT,1,20,param1=20,param2=8,
                                   minRadius=0,maxRadius=60)    
        index = 0
        if circles is not None:
            # convert the (x, y) coordinates and radius of the circles to integers
            circles = numpy.round(circles[0, :]).astype("int")
    
            # loop over the (x, y) coordinates and radius of the circles
            for (x, y, r) in circles:
                # draw the circle in the output image, 
                #   then draw a rectangle corresponding to the center of the circle
                cv2.circle(output, (x, y), r, (255, 0, 255), 2)
                cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (255, 0, 255), -1)
    
                index = index + 1
                #print str(index) + " : " + str(r) + ", (x,y) = " + str(x) + ', ' + str(y)
            print 'No. of circles detected = {}'.format(index)
    

    Hope this help.

    這篇關于計算圖像中的彩色點的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 午夜视频在线 | 精品1区2区3区4区 | 曰韩三级 | 久草新在线| 男人久久天堂 | 免费久久久久久 | 国产精品地址 | 日日夜夜操天天干 | 久久国产欧美日韩精品 | 欧美精品二区 | 亚欧精品一区 | 国产在线不卡 | 亚洲综合久久久 | 玖玖精品视频 | 中文字幕欧美一区 | 91视频网址 | 久久激情五月丁香伊人 | 国产一区 | 91亚洲国产成人久久精品网站 | 久久青 | 国产综合久久久久久鬼色 | 在线观看日本网站 | 午夜电影福利 | av片网站| www日本在线观看 | 久久99精品国产自在现线小黄鸭 | 久久骚 | 亚洲va欧美va人人爽午夜 | 国产精品精品久久久 | 人人性人人性碰国产 | 日韩在线视频一区二区三区 | 国产一二三区免费视频 | 欧美一区二区免费电影 | 精品国产一区二区三区av片 | 久久久国产精品视频 | 日韩一区二区三区精品 | 欧美日产国产成人免费图片 | 亚洲精品久久区二区三区蜜桃臀 | 亚洲一区二区在线视频 | 成人免费视频网站在线观看 | 北条麻妃一区二区三区在线观看 |