0

As I studied so far Canny is an edge detection algorithm and Hog is a feature extraction method. In openCV I saw some implementation of Hog feature extraction with Sobel kernels:

import numpy as np
import cv2

img = cv2.imread("")
img = np.float32(img) / 255.0

gx = cv2.Sobel(img, cv2.CV_32F, 1, 0, ksize=1)
gy = cv2.Sobel(img, cv2.CV_32F, 0, 1, ksize=1)

mag, angle = cv2.cartToPolar(gx, gy, angleInDegrees=True)
print(mag)

Instead of using Sobel is there a way to use Canny alogorithm to calculate gradients for HOG? My goal is to detect cloths in images.

YakovL
  • 7,557
  • 12
  • 62
  • 102
Ravinda Lakshan
  • 1,006
  • 14
  • 14
  • 5
    it would be better if you post text output instead of image it is much easier to analyze. Could you include in your question the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Artem Sep 22 '18 at 10:51
  • 1
    HoG describes an image region with histogram of oriented gradients. Do you want to describe the image by histograms of oriented edges? Probably this could work, but gradient is finer, you have more information there... So depends on your problem and how you implement it – Micka Sep 22 '18 at 13:22
  • Yes, like Artem has pointed, to answer "can we use Canny instead of Sobel?" we need to know what result do you expect; and what you have tried so far, too (was there any problem with using it?) – YakovL Sep 22 '18 at 21:30
  • @YakovL I'm using Hog features to train SVM to detect cloths in images. and yes I want to use the hog features but most of the implementation on the internet i see using sobel kernels. Since Canny is known as a better algorithm than Sobel I want to is there a way to use canny algorithm to extract HOG features. – Ravinda Lakshan Sep 23 '18 at 05:14
  • 1
    "Since Canny is known as a better algorithm than Sobel" no it isn't, these are two completely different things. Canny is an edge detector, Sobel is a convolutional kernel to give an approximation to a derivative/gradient. The Canny edge detector in fact generally uses Sobel itself. – alkasm Sep 23 '18 at 06:09
  • @AlexanderReynolds. Thanks for the clarification. When training a SVM to recognize an object in an image can we use output of canny instead of going for hog features ? – Ravinda Lakshan Sep 23 '18 at 09:31
  • Doesn't seem like a good idea to me considering the hyperparameters of Canny; at that point just seems like you should use a CNN since it can (likely will) do its own edge detection. But I'm just a random person on the internet. Maybe it's worth trying? – alkasm Sep 23 '18 at 13:18

0 Answers0