def cvimage_to_string(image, quality=None):
    """Convert opencv image format to bytes."""
    import cv2
    if quality is None:
        dummy, imagedata = cv2.imencode('.jpg', image)
    else:
        dummy, imagedata = cv2.imencode('.jpg', image, [int(cv2.
            IMWRITE_JPEG_QUALITY), quality])
    if imagedata is None:
        return None
    else:
        return imagedata.tostring()
