0

I have trained my own cascade of cycles and trying to detect cycle in image and it is not working. I am using following code. While training cascade I used image size 24 X 24. used 20 negative images and 15 positive images.

import cv2
import numpy as np
import os

path = os.path.dirname(os.getcwd())

# Trained haar cascade for objects o be identified
filename = path+'\\Object_detection_image\\cycle_detector.xml'

# Load the face cascade file
cascade = cv2.CascadeClassifier(filename)

# Check if the face cascade file has been loaded
# if face_cascade.empty():
#   raise IOError('Unable to load the face cascade classifier xml file')

# Define the scaling factor
scaling_factor = 1.0

# Select image for testing.
filepath = path+'\\Object_detection_image\\images\\test\\1a.bmp'

# Read image for test
image = cv2.imread(filepath, 0)



cv2.imshow("Input Image", image)

frame = cv2.resize(image, None, fx=scaling_factor, fy=scaling_factor,  
interpolation=cv2.INTER_AREA)


# Run the face detector on the grayscale image 
# FOLLOWING CODE ALWAYS RETURNING BLANK TUPLE.
rects = cascade.detectMultiScale(frame)


# Draw rectangles on the image
for (x,y,w,h) in rects:
   cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 3)

# Display the image
cv2.imshow('Face Detector', frame)

# Check if Esc key has been pressed
cv2.waitKey(0)
cv2.destroyAllWindows()

Sample Image

enter image description here

rayryeng
  • 102,964
  • 22
  • 184
  • 193
Rajan Sharma
  • 325
  • 1
  • 4
  • 11

0 Answers0