获取图像中圆圈的坐标

时间:2018-04-26 00:03:46

标签: python r image edge

我试图在它们被抛出(Example 1Example 2)之后提取冰壶岩石中心的坐标,最好保存为.csv。

我一直在使用R,因为我对它感觉更舒服,但如果效果更好,Python解决方案会很棒。

我的代码主要基于这些资源(thisthis),但在识别坐标方面效果不佳。我只想要大的红色/黄色圆圈(不是在顶部或底部分组的圆圈)。我宁愿不裁剪小岩石的位置,因为我需要图像的精确坐标以供日后使用。

当前的代码正在对一些靠近的大石头进行分组,例如示例2,显示为here,这使得中心完全错误,如here。因此,虽然它通常会找到岩石,但它并没有准确地找到它们,因此给我错误的坐标。

我也放了我的代码,但我没有投入代码 - 无论使用何种解决方案,无论用什么语言,我都很好!

library(dplyr)
library(imager)
library(ggplot2)

im <- load.image("https://i.stack.imgur.com/3tDtR.png")
d <- as.data.frame(im)
m <- sample_n(d,1e4) %>% lm(value ~ x*y,data=.) 
im.c <- im-predict(m,d)
out <- threshold(im.c) 
plot(out)

df <- as.data.frame(out)

out <- clean(out,3) %>% imager::fill(7)

plot(im)
highlight(out)

df <- (out %>% label) %>%
  as.data.frame()

get.centers <- function(dt)
{
  dt %>% subset(value>0) %>% dplyr::group_by(value) %>% dplyr::summarise(mx=mean(x),my=mean(y))
}

centers <- get.centers(df)
plot(im)

points(centers$mx,centers$my)

0 个答案:

没有答案
相关问题