python - OpenCV detection with different colorspace -


i using opencv detect objects cascade classifiers trained on grayscale images , testing detection on different color spaces (images color) , calculating precision/recall/harmonic mean.
im wondering why same results greyscale , rgb different in other colorspaces?

      # read image     image = cv2.imread(imagepath)       # convert grayscale (default algorithm)     if colorspace == "gray":         colorcvt = cv2.cvtcolor(image, cv2.color_bgr2gray)     elif colorspace == "hsv":         colorcvt = cv2.cvtcolor(image, cv2.color_bgr2hsv)     elif colorspace == "hls":         colorcvt = cv2.cvtcolor(image, cv2.color_bgr2hls)     elif colorspace == "lab":         colorcvt = cv2.cvtcolor(image, cv2.color_bgr2lab)     elif colorspace == "luv":         colorcvt = cv2.cvtcolor(image, cv2.color_bgr2luv)     elif colorspace == "yuv":         colorcvt = cv2.cvtcolor(image, cv2.color_bgr2yuv)     elif colorcvt --"rgb"         colorspace = cv2.cvtcolor(image, cv2.color_bgr2rgb)     else:         colorcvt = image      print('using color mode: '+colorspace)      open(outputfilename, 'a') results:         results.write("running detection on image:  "+imagepath +"\n")         results.write("detecting using trained classifier: "+cascadepath +"\n")     # results.close()       # training params     scale_factor = 1.02     min_neighbors = 5     min_size = (10,10)     max_size = (128,128)      # detect objects in image     objects = trainedcascade.detectmultiscale(         colorcvt,         scalefactor=scale_factor,         minneighbors=min_neighbors,         minsize=min_size,         maxsize=max_size,         flags = cv2.cv.cv_haar_scale_image     ) 

if @ api detectmultiscale, see expects image grayscale. assume if encounters 3-channel image (be bgr, hsv, or whatever), tries conversion grayscale first.

unfortunately, when presented 3-channel image, opencv has no way of knowing colorspace image using since there no metadata indicate such thing. limitation apparent in cvtcolor call have specify both source , destination colorspaces. in case of 3-channel image argument detectmultiscale, appears guess rgb (or maybe bgr? code on bgr2rgb seems buggy) colorspace, , of course correct if colorspace.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -