1

I am trying to extract hog descriptors for some ROI on a given image (2D) using the implementation in OpenCV. I have attached some samples of the ROI that I have extracted. I am just using the hog descriptor with all the default values.

Configuration: python:3.9.13; opencv-python 4.7.0; Windows 10

An error is thrown as follows.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: vector<T> too long

NOTE: I want to use the HOG descriptors from positive and negative sample to train and Linear SVM model.

Sample ROI positive sample negative sample

Code to reproduce problem

import cv2 as cv
hog = cv.HOGDescriptor()
img = cv.imread(<path to image>, cv.IMREAD_GRAYSCALE)
desc = hog.compute(img)

I do understand that there is a limit on vector size but the image size is really not that big which is 193 X 16 (width X height)

Is there a workaround to this problem or am I messing up somewhere?

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
tintin98
  • 91
  • 9
  • The error message made me think you’re trying C++ now. :) – Cris Luengo Jul 13 '23 at 19:54
  • It is likely that OpenCV's HOG descriptor is failing for [the same reason as skimage's is](https://stackoverflow.com/a/76682937/7328782) (but in a less graceful way): your blocks are too large for the image. – Cris Luengo Jul 13 '23 at 20:13
  • However, here the vector size is exceeding the limit. Its not an empty vector if we try to find the analogy with the skimage issue. – tintin98 Jul 13 '23 at 20:32
  • I submitted an issue to the OpenCV project as well: https://github.com/opencv/opencv/issues/23989 – Cris Luengo Jul 13 '23 at 20:34
  • The error message you see is something internally going wrong because the code is not expecting to produce a zero-size output. It is internal because it references a C++ type, OpenCV typically doesn't do that if it gets the wrong input. -- If you make the input larger, it doesn't error out. I guess you can change the block size like in skimage, but I didn't bother figuring out how to do that. – Cris Luengo Jul 13 '23 at 20:35
  • Yea no problem. I can work on it now that I know what's the root cause. – tintin98 Jul 13 '23 at 20:52
  • @CrisLuengo should I delete this question or just let it be? – tintin98 Jul 16 '23 at 13:58
  • 1
    Feel free to leave it open. If you have a workaround you can post it as an answer. – Cris Luengo Jul 16 '23 at 14:23

0 Answers0