我正在使用YOLO做一个机器学习项目。我正在创建自己的数据集,遵循“找到这里”指南(在部分,如何训练(以检测自定义对象))。对于包围框,我需要知道我想在给定的图片中训练YOLO的每个对象的x宽度。到目前为止,我已经找到了手工,但它正在变得非常耗时。我希望能得到一些帮助,写一个脚本,可以为我计算这个。我知道opencv有一些很好的图像处理工具,但不知道从哪里开始寻找对象坐标。
发布于 2018-03-06 05:02:36
在您提到的页面中,有一个部分包含指向执行这些框的工具的链接:
如何标记对象的有界框并创建注释文件: 在这里,您可以找到用于标记有界对象框和为Yolo v2:标记生成注释文件的GUI软件存储库。
发布于 2019-01-11 11:46:13
我也面临着同样的问题,但在我的例子中,数据是视频的,背景是一样的,所以我做了背景减法,你可以通过调整一些阈值来尝试这个代码,也许你可以得到你想要的。
import cv2
import numpy as np
# read and scale down image
# wget https://bigsnarf.files.wordpress.com/2017/05/hammer.png
img = cv2.pyrDown(cv2.imread('hammer.png', cv2.IMREAD_UNCHANGED))
# threshold image
ret, threshed_img = cv2.threshold(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY),
127, 255, cv2.THRESH_BINARY)
# find contours and get the external one
image, contours, hier = cv2.findContours(threshed_img, cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
# with each contour, draw boundingRect in green
# a minAreaRect in red and
# a minEnclosingCircle in blue
for c in contours:
# get the bounding rect
x, y, w, h = cv2.boundingRect(c)
# draw a green rectangle to visualize the bounding rect
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2)
# get the min area rect
rect = cv2.minAreaRect(c)
box = cv2.boxPoints(rect)
# convert all coordinates floating point values to int
box = np.int0(box)
# draw a red 'nghien' rectangle
cv2.drawContours(img, [box], 0, (0, 0, 255))
# finally, get the min enclosing circle
(x, y), radius = cv2.minEnclosingCircle(c)
# convert all values to int
center = (int(x), int(y))
radius = int(radius)
# and draw the circle in blue
img = cv2.circle(img, center, radius, (255, 0, 0), 2)
print(len(contours))
cv2.drawContours(img, contours, -1, (255, 255, 0), 1)
cv2.imshow("contours", img)
ESC = 27
while True:
keycode = cv2.waitKey()
if keycode != -1:
keycode &= 0xFF
if keycode == ESC:
break
cv2.destroyAllWindows()发布于 2020-06-14 22:32:05
这里有一些来自尤洛-马克-普瓦源代码的部分,如您所见,它比原始的Yolo_mark (在右角单击github图标,在检查src/utils/createExportCord.ts,src/utils/readExportCord.ts之后)可读性强得多。naturalWidth和naturalWidth是图像大小,height和width是蓝色矩形大小。
namespace mark {
export namespace utils {
export const createExportCord = ({
name, height, width, top, left, naturalHeight, naturalWidth
}) => {
console.log({name, height, width, top, left, naturalHeight, naturalWidth});
const x = (left + (width/2)) / naturalWidth;
const y = (top + (height/2)) / naturalHeight;
const w = width / naturalWidth;
const h = height / naturalHeight;
return [name, x, y, w, h].join(' ');
}
} // namespace utils
} // namespace mark

https://stackoverflow.com/questions/49122356
复制相似问题