cvtcolor in Cv2 - no attribute

16,580

In cv2 function cvtcolor renamed to cvtColor. So you should use RgbImage = cv2.cvtColor(ave_image,cv2.COLOR_BGR2RGB)

Share:
16,580
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm writing a program to collect a series of images from a USB microscope and generate an average as a way of denoising. I'm having to convert the image into a numpy array, sum the pixels then divide before converting back to an image.

    Somewhere along the line the channels get mixed so my output is BGR not RGB, I'm trying to use cvtcolor to rectify that but get the error:

    ---> 55 RgbImage = cv2.cvtcolor(ave_image,cv2.COLOR_BGR2RGB) 56 return RgbImage

    AttributeError: 'module' object has no attribute 'cvtcolor'

    Presumably cvtcolour isn't being imported from CV2 but I can't see why. Here's the relevant code sections.

    Lastly, although the averaging works fine, is there a more elegant way to do it? I need a simple mean not a weighted average.

    import os, numpy, PIL
    from PIL import Image
    import cv2
    import time
    frameaverage=5
    
    
     def average_image():
    
     arr=numpy.zeros((h,w,3),numpy.float)
     # Build up average pixel intensities as floating
     for im in xrange(frameaverage):
        camera_capture = get_image()
        imarr=numpy.array(camera_capture,dtype=numpy.float)
        arr=arr+imarr/frameaverage
     # Round values convert to 8-bit integer
     arr=numpy.array(numpy.round(arr),dtype=numpy.uint8)
     ave_image=Image.fromarray(arr,mode="RGB")
     RgbImage = cv2.cvtcolor(ave_image,cv2.COLOR_BGR2RGB)
     return RgbImage
    
  • Admin
    Admin almost 10 years
    cheers, that fixed the original error but produced another about the object not being a numpy array so I had to tweak it a little bit more >RgbImage = cv2.cvtColor(arr,cv2.COLOR_BGR2RGB) >ave_image=Image.fromarray(RgbImage,mode="RGB")