- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试改进我的代码以查找网球场线截距,以便我可以找到球场不同象限的边界。
输入图像
输出图像
我通过首先找到图像中的白色像素,然后应用 Canny 边缘检测和一些预处理(例如高斯模糊)来实现这一点。然后放大 canny edge 输出以帮助为 hough 线检测做好准备。
然后采用 hough 线输出我使用了 Bentley–Ottmann algorithm 的 python 实现由 github 用户 ideasman42 找到 hough 线截距。
这似乎工作得很好,但我正在努力调整我的系统以找到最后 4 个拦截点。如果有人可以给我建议以改进或调整此实现,甚至提供一些想法以更好地解决寻找法院边界的问题,我将不胜感激。
# import the necessary packages
import numpy as np
import argparse
import cv2
import scipy.ndimage as ndi
import poly_point_isect as bot
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", help = "path to the image")
args = vars(ap.parse_args())
# load the image
image = cv2.imread(args["image"])
# define the list of boundaries
boundaries = [
([180, 180, 100], [255, 255, 255])
]
# loop over the boundaries
for (lower, upper) in boundaries:
# create NumPy arrays from the boundaries
lower = np.array(lower, dtype = "uint8")
upper = np.array(upper, dtype = "uint8")
# find the colors within the specified boundaries and apply
# the mask
mask = cv2.inRange(image, lower, upper)
output = cv2.bitwise_and(image, image, mask = mask)
# show the images
cv2.imshow("images", np.hstack([image, output]))
cv2.waitKey(0)
gray = cv2.cvtColor(output,cv2.COLOR_BGR2GRAY)
kernel_size = 5
blur_gray = cv2.GaussianBlur(gray,(kernel_size, kernel_size),0)
low_threshold = 10
high_threshold = 200
edges = cv2.Canny(gray, low_threshold, high_threshold)
dilated = cv2.dilate(edges, np.ones((2,2), dtype=np.uint8))
cv2.imshow('dilated.png', dilated)
cv2.waitKey(0)
rho = 1 # distance resolution in pixels of the Hough grid
theta = np.pi / 180 # angular resolution in radians of the Hough grid
threshold = 10 # minimum number of votes (intersections in Hough grid cell)
min_line_length = 40 # minimum number of pixels making up a line
max_line_gap = 5 # maximum gap in pixels between connectable line segments
line_image = np.copy(output) * 0 # creating a blank to draw lines on
# Run Hough on edge detected image
# Output "lines" is an array containing endpoints of detected line segments
lines = cv2.HoughLinesP(dilated, rho, theta, threshold, np.array([]), min_line_length, max_line_gap)
points = []
for line in lines:
for x1, y1, x2, y2 in line:
points.append(((x1 + 0.0, y1 + 0.0), (x2 + 0.0, y2 + 0.0)))
cv2.line(line_image, (x1, y1), (x2, y2), (255, 0, 0), 5)
cv2.imshow('houghlines.png', line_image)
cv2.waitKey(0)
lines_edges = cv2.addWeighted(output, 0.8, line_image, 1, 0)
print(lines_edges.shape)
intersections = bot.isect_segments(points)
print(intersections)
for idx, inter in enumerate(intersections):
a, b = inter
match = 0
for other_inter in intersections[idx:]:
c, d = other_inter
if abs(c-a) < 8 and abs(d-b) < 8:
match = 1
if other_inter in intersections:
intersections.remove(other_inter)
intersections[idx] = ((c+a)/2, (d+b)/2)
if match == 0:
intersections.remove(inter)
for inter in intersections:
a, b = inter
for i in range(6):
for j in range(6):
lines_edges[int(b) + i, int(a) + j] = [0, 0, 255]
# Show the result
cv2.imshow('line_intersections.png', lines_edges)
cv2.imwrite('line_intersections.png', lines_edges)
cv2.waitKey(0)
最佳答案
这是我的解决方案,使用了不同的方法。我使用 Harris 角点检测器来检测角点。参数只是匆忙调整了一下,所以请随意使用它们。 Here是来自 OpenCV 的教程。
我使用 OpenCV Wrapper library对于一些更简单的 OpenCV 代码。如果您不想翻译,应该很容易翻译。
# import the necessary packages
import numpy as np
import cv2
import opencv_wrapper as cvw
# import poly_point_isect as bot
# construct the argument parse and parse the arguments
# load the image
image = cv2.imread("tennis.jpg")
# define the list of boundaries
boundaries = [([180, 180, 100], [255, 255, 255])]
# loop over the boundaries
for (lower, upper) in boundaries:
# create NumPy arrays from the boundaries
lower = np.array(lower, dtype="uint8")
upper = np.array(upper, dtype="uint8")
# find the colors within the specified boundaries and apply
# the mask
mask = cv2.inRange(image, lower, upper)
output = cv2.bitwise_and(image, image, mask=mask)
# Start my code
gray = cvw.bgr2gray(output)
corners = cv2.cornerHarris(gray, 9, 3, 0.01)
corners = cvw.normalize(corners).astype(np.uint8)
thresh = cvw.threshold_otsu(corners)
dilated = cvw.dilate(thresh, 3)
contours = cvw.find_external_contours(dilated)
for contour in contours:
cvw.circle(image, contour.center, 3, cvw.Color.RED, -1)
cv2.imshow("Image", image)
cv2.waitKey(0)
结果:
披露:我是 OpenCV Wrapper 的作者。
关于python - 检测网球场线拦截,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55496402/
我刚开始使用新的拦截方法,有一个基本问题,想知道如何在一个测试中链接下面的两个断言。 cy.intercept('GET', '/states').as('states'); cy.reload(tr
我有一个标签控件的自定义版本(使用用户控件构建)。在设计器中工作时,我想截取 Name 属性的设置(在属性面板中)并使用它来生成 Text 属性。也就是说,如果我在属性面板的 Name 属性中输入“l
嗨,我想通过 soapUI 解析 ssl soap 消息,而我试图通过 HttpMonitor 进行拦截它显示在异常下方 ERROR:Exception in request: javax.net.s
是否有可能从某个任意层拦截反向梯度,修改其值并继续反向传播回到网络的开始,根据您提供的修改后的梯度值更新所有先前层的反向梯度? 我知道你可以directly modify the gradients
我可以从什么 dll 中获得 Intercept 的扩展?我从 http://github.com/danielmarbach/ninject.extensions.interception 添加了
我有一个实现 onCreateOptionsMenu 方法的顶级 TabHost。我希望子 Activity (选项卡内的子 Activity )能够通过 onOptionsItemSelected
我在尝试反序列化 URL 时遇到此错误 Caused by: java.net.MalformedURLException: no protocol: www.boo.com at java.
首先,我是 Spring 的新手,这是我第一次尝试使用 Spring 编写基于 REST 的应用程序。 我计划在请求参数和响应中使用 Json。这让我想到两个问题。 有没有办法将 products="
在我基于 j_security_check 的登录表单中登录时一切正常。在这种情况下,我看到 JSESSIONID cookie 中的路径具有来自 URL 的值。但是当另一个登录页面构造动态表单(它正
我有一个我一直致力于下载文件的程序。一切正常,除非用户使用 AVG。奇怪的是,为了解决这个问题,似乎必须禁用 AVG 的“电子邮件保护”;将我的程序或 JRE 添加到异常(exception)列表不起
我正在寻找一种方法来挂接 SMSManager 或较低级别的机制,以便我可以在发送任何外发 SMS 消息之前拦截、读取和取消它们。 最佳答案 迟到总比不到好:) 我已经在这上面花了 2 天...并且不
我已成功拦截对 read() 的调用, write() , open() , unlink() , rename() , creat()但不知何故截获完全相同的语义stat()没有发生。我已经使用 L
阿里云ECS通过安全组屏蔽/拦截/阻断特定IP对云服务器的访问 所适用的场景: 通过安全组屏蔽、拦截、阻止特定IP对用户云服务器的访问,或者屏蔽IP访问服务器的特定端口。 配置的方法: 1、
我希望能够在类本身的构造函数中代理类的所有方法。 class Boy { constructor() { // proxy logic, do something before
使用 ajax 请求可以使用以下代码完成: let oldXHROpen = window.XMLHttpRequest.prototype.open; window.lastXhr = ''; wi
我想“拦截”/更改将 OData 与 Web API 一起使用时生成的 OData 查询..但我不完全确定如何“提取”生成的查询..我假设 OData 过滤器、扩展和更多一些如何生成某种表达式树或某种
当 JUnit 中的断言失败时,我想做一些“自己的事情”。我想要这个: public class MyAssert extends org.junit.Assert { // @Overrid
如何拦截 PartialFunction?例如在 Actor 中,如果我只想打印进入以下接收方法的所有内容,然后再将其传递给流程方法: class MyActor extends Actor {
我们正在使用 fluentvalidation(带有服务堆栈)来验证我们的请求 DTO。我们最近扩展了我们的框架以接受“PATCH”请求,这意味着我们现在需要仅在补丁包含要验证的字段时才应用验证。 我
我有一个作为 excel 插件运行的 WPF 应用程序,它有这样的可视化树 精益求精 元素主机 WPF 用户控件 WPF 色带条控件 现在,在 excel 中加载插件时,不会启用位于 WPF 功能区栏
我是一名优秀的程序员,十分优秀!