Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Not able to identify the images correctly

Hi team,

I have created haar cascade xml file with some training images. But when I use that to detect the object in a video, it's identifying a black portion in the video as the object where as the object is located at some other place in the video frame.

Could you please help me resolve this issue.

Here is my program:

from __future__ import print_function

import cv2 as cv

import argparse

def detectAndDisplay(frame):

frame_gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)

frame_gray = cv.equalizeHist(frame_gray)

#-- Detect faces

faces = face_cascade.detectMultiScale(frame_gray)

for (x,y,w,h) in faces:

    print('car detected')

    center = (x + w//2, y + h//2)

    frame = cv.ellipse(frame, center, (w//2, h//2), 0, 0, 360, (255, 0, 255), 4)

    faceROI = frame_gray[y:y+h,x:x+w]

cv.imshow('Capture - Face detection', frame)

parser = argparse.ArgumentParser(description='Code for Cascade Classifier tutorial.')

parser.add_argument('--face_cascade', help='Path to face cascade.', default='C:/AdrsTrain/dasar_haartrain/myhaar.xml')

parser.add_argument('--camera', help='Camera devide number.', type=int, default=0)

args = parser.parse_args()

face_cascade_name = args.face_cascade

face_cascade = cv.CascadeClassifier()

-- 1. Load the cascades

if not face_cascade.load('C:/AdrsTrain/dasar_haartrain/myhaar.xml'):

print('--(!)Error loading face cascade')

exit(0)

camera_device = args.camera

-- 2. Read the video stream

cap = cv.VideoCapture('C:/Accident-detection-Project--master/DemoRun/videos/Detectionbk3.mp4')

if not cap.isOpened:

print('--(!)Error opening video capture')

exit(0)

while True:

ret, frame = cap.read()

if frame is None:

    print('--(!) No captured frame -- Break!')

    break

detectAndDisplay(frame)

if cv.waitKey(50) == 27:

    break

cap.release()

cv.destroyAllWindows()

Not able to identify the images correctly

Hi team,

I have created haar cascade xml file with some training images. But when I use that to detect the object in a video, it's identifying a black portion in the video as the object where as the object is located at some other place in the video frame.

Could you please help me resolve this issue.

Here is my program:

from __future__ import print_function

import cv2 as cv

import argparse

def detectAndDisplay(frame):

frame_gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)

frame_gray = cv.equalizeHist(frame_gray)

#-- Detect faces

faces = face_cascade.detectMultiScale(frame_gray)

for (x,y,w,h) in faces:

    print('car detected')

    center = (x + w//2, y + h//2)

    frame = cv.ellipse(frame, center, (w//2, h//2), 0, 0, 360, (255, 0, 255), 4)

    faceROI = frame_gray[y:y+h,x:x+w]

cv.imshow('Capture - Face detection', frame)

parser = argparse.ArgumentParser(description='Code for Cascade Classifier tutorial.')

parser.add_argument('--face_cascade', help='Path to face cascade.', default='C:/AdrsTrain/dasar_haartrain/myhaar.xml')

parser.add_argument('--camera', help='Camera devide number.', type=int, default=0)

args = parser.parse_args()

face_cascade_name = args.face_cascade

face_cascade = cv.CascadeClassifier()

-- 1. Load the cascades

if not face_cascade.load('C:/AdrsTrain/dasar_haartrain/myhaar.xml'):

print('--(!)Error loading face cascade')

exit(0)

camera_device = args.camera

-- 2. Read the video stream

cap = cv.VideoCapture('C:/Accident-detection-Project--master/DemoRun/videos/Detectionbk3.mp4')

if not cap.isOpened:

print('--(!)Error opening video capture')

exit(0)

while True:

ret, frame = cap.read()

if frame is None:

    print('--(!) No captured frame -- Break!')

    break

detectAndDisplay(frame)

if cv.waitKey(50) == 27:

    break

cap.release()

cv.destroyAllWindows()

Not able to identify the images correctly

Hi team,

I have created haar cascade xml file with some training images. But when I use that to detect the object in a video, it's identifying a black portion in the video as the object where as the object is located at some other place in the video frame.

Could you please help me resolve this issue.

Here is my program:

from __future__ import print_function

print_function import cv2 as cv

cv import argparse

argparse def detectAndDisplay(frame):

detectAndDisplay(frame):

    frame_gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)

 frame_gray = cv.equalizeHist(frame_gray)

 #-- Detect faces

 faces = face_cascade.detectMultiScale(frame_gray)

 for (x,y,w,h) in faces:

     print('car detected')

     center = (x + w//2, y + h//2)

     frame = cv.ellipse(frame, center, (w//2, h//2), 0, 0, 360, (255, 0, 255), 4)

     faceROI = frame_gray[y:y+h,x:x+w]

 cv.imshow('Capture - Face detection', frame)

parser = argparse.ArgumentParser(description='Code for Cascade Classifier tutorial.')

tutorial.') parser.add_argument('--face_cascade', help='Path to face cascade.', default='C:/AdrsTrain/dasar_haartrain/myhaar.xml')

default='C:/AdrsTrain/dasar_haartrain/myhaar.xml') parser.add_argument('--camera', help='Camera devide number.', type=int, default=0)

default=0) args = parser.parse_args()

parser.parse_args() face_cascade_name = args.face_cascade

args.face_cascade face_cascade = cv.CascadeClassifier()

-- cv.CascadeClassifier() #-- 1. Load the cascades

cascades if not face_cascade.load('C:/AdrsTrain/dasar_haartrain/myhaar.xml'):

face_cascade.load('C:/AdrsTrain/dasar_haartrain/myhaar.xml'):

    print('--(!)Error loading face cascade')

 exit(0)

camera_device = args.camera

-- args.camera #-- 2. Read the video stream

stream cap = cv.VideoCapture('C:/Accident-detection-Project--master/DemoRun/videos/Detectionbk3.mp4')

cv.VideoCapture('C:/Accident-detection-Project--master/DemoRun/videos/Detectionbk3.mp4') if not cap.isOpened:

cap.isOpened:

    print('--(!)Error opening video capture')

 exit(0)

while True:

True:

    ret, frame = cap.read()

 if frame is None:

     print('--(!) No captured frame -- Break!')

     break

 detectAndDisplay(frame)

 if cv.waitKey(50) == 27:

     break

cap.release()

cv.destroyAllWindows()

cap.release()

cv.destroyAllWindows()