当前位置: 首页>>代码示例>>Python>>正文


Python cv2.IMWRITE_JPEG_QUALITY属性代码示例

本文整理汇总了Python中cv2.IMWRITE_JPEG_QUALITY属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.IMWRITE_JPEG_QUALITY属性的具体用法?Python cv2.IMWRITE_JPEG_QUALITY怎么用?Python cv2.IMWRITE_JPEG_QUALITY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在cv2的用法示例。


在下文中一共展示了cv2.IMWRITE_JPEG_QUALITY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: decode

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def decode(ori_path, img_path, res_path, alpha):
    ori = cv2.imread(ori_path)
    img = cv2.imread(img_path)
    ori_f = np.fft.fft2(ori)
    img_f = np.fft.fft2(img)
    height, width = ori.shape[0], ori.shape[1]
    watermark = (ori_f - img_f) / alpha
    watermark = np.real(watermark)
    res = np.zeros(watermark.shape)
    random.seed(height + width)
    x = range(height / 2)
    y = range(width)
    random.shuffle(x)
    random.shuffle(y)
    for i in range(height / 2):
        for j in range(width):
            res[x[i]][y[j]] = watermark[i][j]
    cv2.imwrite(res_path, res, [int(cv2.IMWRITE_JPEG_QUALITY), 100]) 
开发者ID:linyacool,项目名称:blind-watermark,代码行数:20,代码来源:decode.py

示例2: encode

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def encode(img_path, wm_path, res_path, alpha):
    img = cv2.imread(img_path)
    img_f = np.fft.fft2(img)
    height, width, channel = np.shape(img)
    watermark = cv2.imread(wm_path)
    wm_height, wm_width = watermark.shape[0], watermark.shape[1]
    x, y = range(height / 2), range(width)
    random.seed(height + width)
    random.shuffle(x)
    random.shuffle(y)
    tmp = np.zeros(img.shape)
    for i in range(height / 2):
        for j in range(width):
            if x[i] < wm_height and y[j] < wm_width:
                tmp[i][j] = watermark[x[i]][y[j]]
                tmp[height - 1 - i][width - 1 - j] = tmp[i][j]
    res_f = img_f + alpha * tmp
    res = np.fft.ifft2(res_f)
    res = np.real(res)
    cv2.imwrite(res_path, res, [int(cv2.IMWRITE_JPEG_QUALITY), 100]) 
开发者ID:linyacool,项目名称:blind-watermark,代码行数:22,代码来源:encode.py

示例3: image_detection

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def image_detection(sess, image_path, image_file, colors):
    # Preprocess your image
    image, image_data = preprocess_image(image_path + image_file, model_image_size = (416, 416))
    
    # Run the session with the correct tensors and choose the correct placeholders in the feed_dict.
    # You'll need to use feed_dict={yolo_model.input: ... , K.learning_phase(): 0})
    out_scores, out_boxes, out_classes = sess.run([scores, boxes, classes], feed_dict={yolo_model.input:image_data, K.learning_phase():0})

    # Print predictions info
    print('Found {} boxes for {}'.format(len(out_boxes), image_file))
    
    # Draw bounding boxes on the image file
    image = draw_boxes(image, out_scores, out_boxes, out_classes, class_names, colors)

    # Save the predicted bounding box on the image
    #image.save(os.path.join("out", image_file), quality=90)
    cv2.imwrite(os.path.join("out", "tiny_yolo_" + image_file), image, [cv2.IMWRITE_JPEG_QUALITY, 90])
    
    return out_scores, out_boxes, out_classes 
开发者ID:kaka-lin,项目名称:object-detection,代码行数:21,代码来源:test_tiny_yolo.py

示例4: image_detection

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def image_detection(sess, image_path, image_file, colors):
    # Preprocess your image
    image, image_data = preprocess_image(image_path + image_file, model_image_size = (416, 416))
    
    # Run the session with the correct tensors and choose the correct placeholders in the feed_dict.
    # You'll need to use feed_dict={yolo_model.input: ... , K.learning_phase(): 0})
    out_scores, out_boxes, out_classes = sess.run([scores, boxes, classes], feed_dict={yolov3.input:image_data, K.learning_phase():0})

    # Print predictions info
    print('Found {} boxes for {}'.format(len(out_boxes), image_file))
    
    # Draw bounding boxes on the image file
    image = draw_boxes(image, out_scores, out_boxes, out_classes, class_names, colors)

    # Save the predicted bounding box on the image
    #image.save(os.path.join("out", image_file), quality=90)
    cv2.imwrite(os.path.join("out", "yolov3_" + image_file), image, [cv2.IMWRITE_JPEG_QUALITY, 90])
    
    return out_scores, out_boxes, out_classes 
开发者ID:kaka-lin,项目名称:object-detection,代码行数:21,代码来源:test_yolov3.py

示例5: format_OxBuild

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def format_OxBuild():
    src_image_save_dir = "/Volumes/projects/ImageRetireval/dataset/OxBuild/src/"
    oxbuild_index_file = src_image_save_dir + "index_file.csv"
    index_writer = open(oxbuild_index_file, "w")

    src_image_dir = "/Volumes/projects/ImageRetireval/dataset/OxBuild/not_deal_src/"
    for image_name in os.listdir(src_image_dir):
        if image_name.startswith("."):
            continue
        class_name = image_name.split("_")[0]
        image_data = cv2.imread(src_image_dir + image_name)
        resize_image_data = cv2.resize(image_data, (224, 224), interpolation=cv2.INTER_CUBIC)
        new_image_save_path = src_image_save_dir + image_name
        cv2.imwrite(new_image_save_path, resize_image_data, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
        index_writer.write("{},{}\n".format(image_name, class_name))

# format_OxBuild() 
开发者ID:liuguiyangnwpu,项目名称:MassImageRetrieval,代码行数:19,代码来源:format_dataset.py

示例6: resize

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def resize(images_paths, size=299):
    """
    Function for resizing images.

    :param images_paths:
        Required. Paths to images.

    :param size:
        Optional. Size to which resize to. Defaults to 299.

    :return:
        Nothing.
    """
    for image_path in images_paths:
        image = cv2.imread(image_path)

        # Resize the image.
        image = cv2.resize(image, (size, size))

        # Save the image.
        cv2.imwrite(image_path, image, [int(cv2.IMWRITE_JPEG_QUALITY), 100]) 
开发者ID:mikevoets,项目名称:jama16-retina-replication,代码行数:23,代码来源:preprocess.py

示例7: add_datum

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def add_datum(self, *inds, **datum_dict):
        other_dict = dict([item for item in datum_dict.items() if not item[0].endswith('image')])
        super(ImageDataContainer, self).add_datum(*inds, **other_dict)
        image_dict = dict([item for item in datum_dict.items() if item[0].endswith('image')])
        for image_name, image in image_dict.items():
            if image_name in self.datum_shapes_dict and self.datum_shapes_dict[image_name] != image.shape:
                raise ValueError('unable to add datum %s with shape %s since the shape %s was expected' %
                                 (image_name, image.shape, self.datum_shapes_dict[image_name]))
            self.datum_shapes_dict[image_name] = image.shape
            image_fname = self._get_image_fname(*(inds + (image_name,)))
            if image.dtype == np.uint8:
                if image.ndim == 3 and image.shape[2] == 3:
                    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
            else:
                image = math_utils.pack_image(image)
            cv2.imwrite(image_fname, image, [int(cv2.IMWRITE_JPEG_QUALITY), 100]) 
开发者ID:alexlee-gk,项目名称:visual_dynamics,代码行数:18,代码来源:container.py

示例8: flush

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def flush(self, t, img):
        """

        :param t: the time since start of the experiment, in ms
        :param img: an array representing an image.
        :type img: np.ndarray
        :return:
        """

        tick = int(round((t/1000.0)/self._period))
        if tick == self._last_tick:
            return

        cv2.imwrite(self._tmp_file, img, [int(cv2.IMWRITE_JPEG_QUALITY), 50])

        with open(self._tmp_file, "rb") as f:
                bstring = f.read()
                
        cmd = 'INSERT INTO ' + self._table_name + '(id,t,img) VALUES (%s,%s,%s)'

        args = (0, int(t), bstring)

        self._last_tick = tick

        return cmd, args 
开发者ID:gilestrolab,项目名称:ethoscope,代码行数:27,代码来源:io.py

示例9: detect_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def detect_image(detector, device, args):
    """Demo for detecting images."""
    timer = Timer()
    while True:
        image_file = input('Enter image file path: ')
        image = cv.imread(image_file)
        timer.tic()
        pred_points = detect_marking_points(
            detector, image, args.thresh, device)
        slots = None
        if pred_points and args.inference_slot:
            marking_points = list(list(zip(*pred_points))[1])
            slots = inference_slots(marking_points)
        timer.toc()
        plot_points(image, pred_points)
        plot_slots(image, pred_points, slots)
        cv.imshow('demo', image)
        cv.waitKey(1)
        if args.save:
            cv.imwrite('save.jpg', image, [int(cv.IMWRITE_JPEG_QUALITY), 100]) 
开发者ID:Teoge,项目名称:DMPR-PS,代码行数:22,代码来源:inference.py

示例10: resize_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def resize_image(img_path, mini_size=480, jpeg_quality=80):
    """
    缩放image
    :param img_path: image的路径
    :param mini_size: 最小边的尺寸
    :param jpeg_quality: jpeg图片的质量
    """
    org_img = cv2.imread(img_path)
    img_w = org_img.shape[0]
    img_h = org_img.shape[1]
    if max(img_w, img_h) > mini_size:
        if img_w > img_h:
            img_w = mini_size * img_w // img_h
            img_h = mini_size
        else:
            img_h = mini_size * img_h // img_w
            img_w = mini_size
    dist_size = (img_h, img_w)
    r_image = cv2.resize(org_img, dist_size, interpolation=cv2.INTER_AREA)
    params = [cv2.IMWRITE_JPEG_QUALITY, jpeg_quality]
    img_name = img_path + '_New.jpg'
    cv2.imwrite(img_name, r_image, params=[cv2.IMWRITE_JPEG_QUALITY, params]) 
开发者ID:itaa,项目名称:soja-box,代码行数:24,代码来源:soja_resize_image.py

示例11: set_xseg_mask

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def set_xseg_mask(self, mask_a):
        if mask_a is None:
            self.dfl_dict['xseg_mask'] = None
            return

        mask_a = imagelib.normalize_channels(mask_a, 1)
        img_data = np.clip( mask_a*255, 0, 255 ).astype(np.uint8)

        data_max_len = 4096

        ret, buf = cv2.imencode('.png', img_data)

        if not ret or len(buf) > data_max_len:
            for jpeg_quality in range(100,-1,-1):
                ret, buf = cv2.imencode( '.jpg', img_data, [int(cv2.IMWRITE_JPEG_QUALITY), jpeg_quality] )
                if ret and len(buf) <= data_max_len:
                    break

        if not ret:
            raise Exception("set_xseg_mask: unable to generate image data for set_xseg_mask")

        self.dfl_dict['xseg_mask'] = buf 
开发者ID:iperov,项目名称:DeepFaceLab,代码行数:24,代码来源:DFLJPG.py

示例12: pack_img

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def pack_img(header, img, quality=95, img_fmt='.jpg'):
    """Pack an image into ``MXImageRecord``.

    Parameters
    ----------
    header : IRHeader
        Header of the image record.
        ``header.label`` can be a number or an array. See more detail in ``IRHeader``.
    img : numpy.ndarray
        Image to be packed.
    quality : int
        Quality for JPEG encoding in range 1-100, or compression for PNG encoding in range 1-9.
    img_fmt : str
        Encoding of the image (.jpg for JPEG, .png for PNG).

    Returns
    -------
    s : str
        The packed string.

    Examples
    --------
    >>> label = 4 # label can also be a 1-D array, for example: label = [1,2,3]
    >>> id = 2574
    >>> header = mx.recordio.IRHeader(0, label, id, 0)
    >>> img = cv2.imread('test.jpg')
    >>> packed_s = mx.recordio.pack_img(header, img)
    """
    assert cv2 is not None
    jpg_formats = ['.JPG', '.JPEG']
    png_formats = ['.PNG']
    encode_params = None
    if img_fmt.upper() in jpg_formats:
        encode_params = [cv2.IMWRITE_JPEG_QUALITY, quality]
    elif img_fmt.upper() in png_formats:
        encode_params = [cv2.IMWRITE_PNG_COMPRESSION, quality]

    ret, buf = cv2.imencode(img_fmt, img, encode_params)
    assert ret, 'failed to encode image'
    return pack(header, buf.tostring()) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:42,代码来源:recordio.py

示例13: _augment

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def _augment(self, img, q):
        enc = cv2.imencode('.jpg', img, [cv2.IMWRITE_JPEG_QUALITY, q])[1]
        return cv2.imdecode(enc, 1).astype(img.dtype) 
开发者ID:tensorpack,项目名称:dataflow,代码行数:5,代码来源:noise.py

示例14: extract_video_opencv

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def extract_video_opencv(v_path, f_root, dim=240):
    '''v_path: single video path;
       f_root: root to store frames'''
    v_class = v_path.split('/')[-2]
    v_name = os.path.basename(v_path)[0:-4]
    out_dir = os.path.join(f_root, v_class, v_name)
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    vidcap = cv2.VideoCapture(v_path)
    nb_frames = int(vidcap.get(cv2.CAP_PROP_FRAME_COUNT))
    width = vidcap.get(cv2.CAP_PROP_FRAME_WIDTH)   # float
    height = vidcap.get(cv2.CAP_PROP_FRAME_HEIGHT) # float
    if (width == 0) or (height==0): 
        print(v_path, 'not successfully loaded, drop ..'); return
    new_dim = resize_dim(width, height, dim)

    success, image = vidcap.read()
    count = 1
    while success:
        image = cv2.resize(image, new_dim, interpolation = cv2.INTER_LINEAR)
        cv2.imwrite(os.path.join(out_dir, 'image_%05d.jpg' % count), image,
                    [cv2.IMWRITE_JPEG_QUALITY, 80])# quality from 0-100, 95 is default, high is good
        success, image = vidcap.read()
        count += 1
    if nb_frames > count:
        print('/'.join(out_dir.split('/')[-2::]), 'NOT extracted successfully: %df/%df' % (count, nb_frames))
    vidcap.release() 
开发者ID:TengdaHan,项目名称:DPC,代码行数:30,代码来源:extract_frame.py

示例15: encode_jpg

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import IMWRITE_JPEG_QUALITY [as 别名]
def encode_jpg(image, quality):
    return cv2.imencode(".jpg", image, [cv2.IMWRITE_JPEG_QUALITY, quality])[1].tostring() 
开发者ID:notkarol,项目名称:derplearning,代码行数:4,代码来源:util.py


注:本文中的cv2.IMWRITE_JPEG_QUALITY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。