Ask Your Question
-2

OpenCV cv::cvtColor Error

asked 2018-11-16 14:30:06 -0500

import cv2 import numpy as np

img = cv2.imread('yuz1.jpg')

frontal = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

gray = cv2.cvtColor(img, cv2.COLOR_BAYER_BG2BGR)

f_face = frontal.detectMultiScale((gray, 1.1, 4))

for (x, y, w, h) in f_face: cv2.rectangle(img(x, y), (x + y + w + h), (0, 255, 0), 3)

cv2.imshow('Frontal Face', img) cv2.waitKey(0) img.release() cv2.destroyAllWindows()

@berak

edit retag flag offensive close merge delete

Comments

and as usual, why do those python noobs NEVER check, if imread() succeeded ?

berak gravatar imageberak ( 2018-11-17 03:56:19 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-11-16 14:58:11 -0500

kbarni gravatar image

Read the docs about the cvtColor function and its parameters!

You certainly wanted to use cv2.COLOR_BGR2GRAY (as the jpg image is certainly not a Bayer image).

edit flag offensive delete link more

Comments

Thank you for your answer. What file extension should I use?

bugrahanozdemir gravatar imagebugrahanozdemir ( 2018-11-16 15:02:27 -0500 )edit
1

@bugrahanozdemir it's not about file extensions, but about colorspaces.

berak gravatar imageberak ( 2018-11-17 03:55:30 -0500 )edit

How am I supposed to make a change?

bugrahanozdemir gravatar imagebugrahanozdemir ( 2018-11-17 13:27:03 -0500 )edit

oh my. what if you finally try to read the answer above ?

berak gravatar imageberak ( 2018-11-18 02:23:14 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-11-16 14:30:06 -0500

Seen: 29 times

Last updated: Nov 16