简体   繁体   English

如何使用OpenCV(python)检测此图像中的岩石?

[英]How can I detect rocks in this image using OpenCV (python)?

I am trying to find the differently shaped rocks in this image. 我试图在这张图片中找到不同形状的岩石。

image http://mars.nasa.gov/mer/gallery/all/2/n/1850/2N290598950EDNB0F8F0006L0M1.JPG 图片http://mars.nasa.gov/mer/gallery/all/2/n/1850/2N290598950EDNB0F8F0006L0M1.JPG

I didn't get any satisfactory results from edge detection. 我没有从边缘检测中得到任何令人满意的结果。

在此输入图像描述

I did read about grabcut but again nothing satisfactory from that either. 我确实读过关于抓取的但是再也没有令人满意的。 Any ideas on how I should proceed? 关于我应该如何进行的任何想法?

PS - My ultimate goal is to mark these rocks in the image with a different color. PS - 我的最终目标是用不同的颜色标记图像中的这些岩石。

UPDATE 1: Here is the code that I used for edge detection. 更新1:这是我用于边缘检测的代码。

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('image1.JPG',0)
edges = cv2.Canny(img,255,255)

plt.subplot(121),plt.imshow(img,cmap = 'gray')
plt.title('Original Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(edges,cmap = 'gray')
plt.title('Edge Image'), plt.xticks([]), plt.yticks([])

plt.show()

UPDATE 2: I have a couple of similar images like the one below in which the rocks (big in size) are clearly visible. 更新2:我有几个类似的图像,如下图所示,其中岩石(大尺寸)清晰可见。 Edge detection is again producing unsatisfactory results on the image. 边缘检测再次在图像上产生不令人满意的结果。 I am just looking for approaches which I can try. 我只是在寻找可以尝试的方法。 If you suggest an approach then please add the relevant links where I can read up more, I am new to opencv. 如果你建议一种方法,那么请添加相关链接,我可以阅读更多,我是opencv的新手。

http://mars.nasa.gov/mer/gallery/all/2/p/2190/2P320875706EFFB27MP2400L5M5-BR.JPG http://mars.nasa.gov/mer/gallery/all/2/p/2190/2P320875706EFFB27MP2400L5M5-BR.JPG

The rocks are segments of the image that are more plain than the sand pieces. 岩石是图像的一部分,比沙子更平坦。 You could try to get each line of the file, divide it in small segments, and compute the Kurtosis of the segment. 您可以尝试获取文件的每一行,将其划分为小段,并计算段的峰度。

The Kurtosis is a measure of the "height" and "width" of the bell-curve of frequencies of values in the segment. 峰度是对段中值的频率的钟形曲线的“高度”和“宽度”的度量。 Sand will have significantly lower Kurtosis than the Rocks, since it has a "broader" spectrum of frequencies. 由于它具有“更广泛”的频谱范围,因此沙子的峰度将明显低于岩石。 Segments with high Kurtosis will likely belong to rocks. 具有高峰度的区段可能属于岩石。

So it will be a matter of determining the ideal length of the segments that each line of the image will have to be divided into. 因此,确定图像的每一行必须被分成的段的理想长度是一个问题。 Not a trivial task, but not a hard one either. 这不是一项微不足道的任务,但也不是一项艰巨的任务。 Half the width of the smallest rock you want to identify (but at least 100 times the width of a grain of sand) should do the trick. 你要识别的最小岩石宽度的一半(但至少是一粒沙子宽度的100倍)应该可以解决问题。

From a 2- d picture ... Really challenging. 从二维图片......真的很有挑战性。 I bet using 2 pictures with an offset is how it can be done much easier processed as a stereoscopic image. 我打赌使用2张带偏移的图片是如何做得更容易处理为立体图像。 Lagging that, I would suggest following strategies: 滞后,我建议遵循以下策略:

  1. Preprocessing to filter out noise outliers - median 预处理以滤除噪声异常值 - 中位数
  2. Maybe use a 2-d band pass filter to sort out rocks of a certain caliber. 也许使用2-d带通滤波器来挑选出某种口径的岩石。
  3. Use the edge detection you did - seems to have done an excellent job. 使用你做的边缘检测 - 似乎做得很好。
  4. Use algorithms that can identify clusters out of your vertices 使用可以识别顶点之外的群集的算法
  5. Combine points or vertices in your cluster using convex hull or voronoi. 使用凸包或voronoi组合群集中的点或顶点。

That being said, I doubt that this forum is suitable to seek an answer to your question, as it is very hard to provide a straight forward answer using coding. 话虽如此,我怀疑这个论坛是否适合寻找你的问题的答案,因为很难用编码提供直截了当的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM