如何求桌子腿的数量

发布于 2025-01-13 14:57:27 字数 1222 浏览 0 评论 0 原文

我真的很困惑,我有这张图片 在此处输入图像描述 我需要找到腿的数量。这意味着,当我执行代码时,输​​出会给我“4” 我尝试了两种方法,其中一种使用边缘检测器

# import the required library
import numpy as np
import cv2
from matplotlib import pyplot as plt

class Point:
    x = 0
    y = 0

# read the image
img = cv2.imread('Table.png')
  
# convert image to gray scale image
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  
# detect corners with the goodFeaturesToTrack function.
corners = cv2.goodFeaturesToTrack(gray, 27, 0.01, 10)
corners = np.int0(corners)
  
# we iterate through each corner, 
# making a circle at each point that we think is a corner.
for i in corners:
    x, y = i.ravel()
    print("x: " + str(x) + " y: " + str(y))
    cv2.circle(img, (x, y), 3, 255, -1)
  
plt.imshow(img), plt.show()

我编写了这段代码并得到了这个结果

在此处输入图像描述 但我不知道之后我会做什么。你们能给我一条路线吗?但在完成我的问题之前,我还尝试了精明算法,它绘制所有表格并给我一个“1”结果。如果我可以将桌子的所有部分分开,也许可以找到桌腿的数量。无论如何我仍然很困惑。

I am really stuck about this, I have this image enter image description here
and I need to find number of legs. It means, when I execute the code, the output would give me "4"
and I tried 2 ways one of it with the edge detector

# import the required library
import numpy as np
import cv2
from matplotlib import pyplot as plt

class Point:
    x = 0
    y = 0

# read the image
img = cv2.imread('Table.png')
  
# convert image to gray scale image
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  
# detect corners with the goodFeaturesToTrack function.
corners = cv2.goodFeaturesToTrack(gray, 27, 0.01, 10)
corners = np.int0(corners)
  
# we iterate through each corner, 
# making a circle at each point that we think is a corner.
for i in corners:
    x, y = i.ravel()
    print("x: " + str(x) + " y: " + str(y))
    cv2.circle(img, (x, y), 3, 255, -1)
  
plt.imshow(img), plt.show()

I wrote this code and get this result

enter image description here
but I don't know what will I do after that. Can you guys give me a route. But before finish my question, I also tried canny algorithm and It draw all table and give me a "1" for result. If I can seperate the all part of table maybe can find number of legs. anyway I am still confused.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文