基本上我创建了返回hog的slice函数 我试着自己解决,但我失败了。如果有人熟悉这种类型的错误,并解决了这个请帮助我。 代码如下:
start_frame = cv2.imread("../train/abnormal_activity/act100014.jpg")
sourcer = FeatureHelp(feature_params, start_frame)
f = sourcer.features(start_frame)
print("feature shape:", f.shape)
rgb_img, a_img, b_img, c_img = sourcer.visualize()
show_images([rgb_img, a_img, b_img, c_img], per_row = 4, per_col = 1, W = 10, H = 2)
错误行是f = source .features(start_frame) 这一行就是这段代码
from skimage.feature import hog
import numpy as np
from helper import convert, show_images
class FeatureHelp:
# json object assign
def __init__(self, p, start_frame):
self.color_model = p['color_model']
self.size = p['bounding_box_size']
self.ori = p['number_of_orientations']
self.ppc = (p['pixel_per_cell'], p['pixel_per_cell'])
self.cpb = (p['cell_per_block'], p['cell_per_block'])
self.do_sqrt = p['do_transform_sqrt']
self.ABC_img = None
self.dims = (None, None, None)
self.hogA, self.hogB, self.HogC = None, None, None
self.hogA_img, self.hogB_img, self.hogC_img = None, None, None
self.RGB_img = start_frame
self.new_frame(self.RGB_img)
def hogg(self, channel):
features, hog_img = hog(
channel, orientations = self.ori,
pixels_per_cell = self.ppc,
cells_per_block = self.cpb,
transform_sqrt = self.do_sqrt,
visualize = True
)
return features, hog_img
def new_frame(self, frame):
self.RGB_img = frame
self.ABC_img = convert(frame, src_model = 'rgb', dest_model = self.color_model)
self.hogA, self.hogA_img = self.hogg(self.ABC_img[:, :, 0])
self.hogB, self.hogB_img = self.hogg(self.ABC_img[:, :, 1])
self.hogC, self.hogC_img = self.hogg(self.ABC_img[:, :, 2])
def slice(self, x_pix, y_pix, w_pix, h_pix):
x_start, x_end, y_start, y_end = self.pix_to_hog(x_pix, y_pix, h_pix, w_pix)
hogA = self.hogA[y_start: y_end, x_start: x_end].ravel()
hogB = self.hogB[y_start: y_end, x_start: x_end].ravel()
hogC = self.hogC[y_start: y_end, x_start: x_end].ravel()
hog = np.hstack((hogA, hogB, hogC))
return hog
def features(self, frame):
self.new_frame(frame)
return self.slice(0, 0, frame.shape[1], frame.shape[0])
def visualize(self):
return self.RGB_img, self.hogA_img, self.hogB_img, self.hogC_img
def pix_to_hog(self, x_pix, y_pix, h_pix, w_pix):
if h_pix is None and w_pix is None:
h_pix, w_pix = self.size, self.size
h = h_pix // self.ppc[0]
w = w_pix // self.ppc[0]
y_start = y_pix // self.ppc[0]
x_start = x_pix // self.ppc[0]
y_end = y_start + h - 1
x_end = x_start + w - 1
return x_start, x_end, y_start, y_end
这部分的问题是
def new_frame(self, frame):
self.RGB_img = frame
self.ABC_img = convert(frame, src_model = 'rgb', dest_model = self.color_model)
self.hogA, self.hogA_img = self.hogg(self.ABC_img[:, :, 0])
self.hogB, self.hogB_img = self.hogg(self.ABC_img[:, :, 1])
self.hogC, self.hogC_img = self.hogg(self.ABC_img[:, :, 2])
def slice(self, x_pix, y_pix, w_pix, h_pix):
x_start, x_end, y_start, y_end = self.pix_to_hog(x_pix, y_pix, h_pix, w_pix)
hogA = self.hogA[y_start: y_end, x_start: x_end].ravel()
hogB = self.hogB[y_start: y_end, x_start: x_end].ravel()
hogC = self.hogC[y_start: y_end, x_start: x_end].ravel()
hog = np.hstack((hogA, hogB, hogC))
return hog
def features(self, frame):
self.new_frame(frame)
return self.slice(0, 0, frame.shape[1], frame.shape[0])
错误: 在这里. . 请帮我解决这个问题。 问题来源StackOverflow 地址:/questions/59384865/i-was-doing-some-hog-feature-extraction-and-got-this-error-indexerror-too-many
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
我想是打错了。 在错误的回溯中显示。
hogA = self.hogA[y_start, y_end, x_start, x_end].ravel()
但是在你的帖子里,你有,这确实是正确的。
hogA = self.hogA[y_start: y_end, x_start: x_end].ravel()