簡體   English   中英

檢測洋蔥田中的洋蔥坐標?

[英]Detecting the onion co-ordinates in an onion field?

由於缺乏數據,我被要求實施一種非數據驅動的方法來查找洋蔥領域中洋蔥的坐標。 該圖像將是一個抬高的前視圖。

這是洋蔥地的圖像:

圖片

我嘗試了以下方法:

img = cv2.imread("/content/Onion1.jpeg",0)
img_blur = cv2.blur(img,(5,5))
edges = cv2.Canny(img_blur,150,200)

最終得到的output:

輸出

我可以通過哪些方法更好地實現目標,即找出圖像中洋蔥的坐標? 我們能否以某種方式利用洋蔥成排種植或其他一些我明顯遺漏的明顯事實? 非常感謝任何幫助/建議。 另外,請注意,我對 OpenCV 非常陌生。

這是使用 k-means 進行的分類,它可以找到洋蔥,因為它們可以通過他的顏色明顯區分,但這通常不適用於其他照片。

它在numClustersToIdentify = 4不同的 colors 中分離圖像

from sklearn.cluster import KMeans
import numpy as np
import cv2
import matplotlib.pyplot as plt


def downloadImage(URL):
    """Downloads the image on the URL, and convers to cv2 BGR format"""
    from io import BytesIO
    from PIL import Image as PIL_Image
    import requests

    response = requests.get(URL)
    image = PIL_Image.open(BytesIO(response.content))
    return cv2.cvtColor(np.array(image), cv2.COLOR_BGR2RGB)


URL = "https://i.stack.imgur.com/eVS6X.jpg"

# Read image
im = downloadImage(URL)


# types of colors to be detected
numClustersToIdentify = 4

# classify the image in types of colors
linearImg = im.reshape((im.shape[1]*im.shape[0], 3))
kmeans = KMeans(n_clusters=numClustersToIdentify)
s = kmeans.fit(linearImg)
imgLabels = s.labels_.reshape(im.shape[0], im.shape[1]).astype(np.uint8)
imgLabels = cv2.normalize(imgLabels, None, 0, 255,
                          cv2.NORM_MINMAX, cv2.CV_8UC1)

cv2.imshow("Image", im)
cv2.waitKey(10)
cv2.imshow("Labels", imgLabels)
cv2.waitKey(10)

fig, ax = plt.subplots(numClustersToIdentify, 1)

for i, label in enumerate(np.unique(imgLabels)):
    ax[i].imshow(imgLabels == label)
    ax[i].axis('off')
plt.show()

在此處輸入圖像描述

我覺得檢測綠色可能是一個很好的起點。

在下圖中,已經使用了 Hue 組件,清楚地顯示了植被和土壤之間的區別。 下一步是找到峰值,這可以通過灰度相關來穩健地實現。 (我們以第二個峰為模板,找到了其他三個;數字是匹配的分數。)

在此處輸入圖像描述 ] 1

在此處輸入圖像描述

現在洋蔥可以通過在山峰尖端附近的一些本地搜索來更精確地定位。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM