OpenCV对象检测未在图像中查找对象

时间:2018-03-21 21:44:07

标签: opencv opencv3.0 opencv3.1

我已经训练了自己的循环级联并试图检测图像中的循环并且它不起作用。我正在使用以下代码。在训练级联时,我使用图像尺寸24 X 24.使用20个负像和15个正像。

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()

示例图像

enter image description here

0 个答案:

没有答案