rot90 ( image, 2 ) elif val = 4 : return np. fliplr ( image ) elif val = 3 : return np. values if val = 1 : return image elif val = 2 : return np. # pip install PyTurboJPEG -U # pip install exifread -U import cv2 import numpy as np import exifread from turbojpeg import TurboJPEG def transposeImage ( image, orientation ): """See Orientation in for details.""" if orientation = None : return image val = orientation. close () # using PyTurboJPEG with ExifRead to transpose an image if the image has an EXIF Orientation tag. close () # lossless crop image out_file = open ( 'lossless_cropped_output.jpg', 'wb' ) out_file. read (), scaling_factor = ( 1, 4 ), quality = 70 )) out_file. waitKey ( 0 ) # scale with quality but leaves out the color conversion step in_file = open ( 'input.jpg', 'rb' ) out_file = open ( 'scaled_output.jpg', 'wb' ) out_file. imshow ( 'gray_array', gray_array ) cv2. read (), pixel_format = TJPF_GRAY ) in_file. close () # decoding input.jpg to grayscale array in_file = open ( 'input.jpg', 'rb' ) gray_array = jpeg. encode ( bgr_array, quality = 100, flags = TJFLAG_PROGRESSIVE )) out_file. out_file = open ( 'output_quality_100_progressive.jpg', 'wb' ) out_file. close () # encoding BGR array to output.jpg with quality level 100 and progressive entropy coding. encode ( bgr_array, quality = 50 )) out_file. out_file = open ( 'output_quality_50.jpg', 'wb' ) out_file. close () # encoding BGR array to output.jpg with quality level 50. encode ( bgr_array, jpeg_subsample = TJSAMP_GRAY )) out_file. out_file = open ( 'output_gray.jpg', 'wb' ) out_file. close () # encoding BGR array to output.jpg with TJSAMP_GRAY subsample. out_file = open ( 'output.jpg', 'wb' ) out_file. close () # encoding BGR array to output.jpg with default settings. close () # decoding input.jpg to YUV planes in_file = open ( 'input.jpg', 'rb' ) planes = jpeg. close () # decoding input.jpg to YUV array in_file = open ( 'input.jpg', 'rb' ) buffer_array, plane_sizes = jpeg. scaling_factors # decoding JPEG image properties in_file = open ( 'input.jpg', 'rb' ) width, height, jpeg_subsample, jpeg_colorspace = jpeg. waitKey ( 0 ) # getting possible scaling factors for direct rescaling scaling_factors = jpeg. imshow ( 'bgr_array_half', bgr_array_half ) cv2. read (), scaling_factor = ( 1, 2 )) in_file. waitKey ( 0 ) # direct rescaling 1/2 while decoding input.jpg to BGR array in_file = open ( 'input.jpg', 'rb' ) bgr_array_half = jpeg. read (), flags = TJFLAG_FASTUPSAMPLE | TJFLAG_FASTDCT ) in_file. fastest speed but lower accuracy) in_file = open ( 'input.jpg', 'rb' ) bgr_array = jpeg. waitKey ( 0 ) # decoding input.jpg to BGR array with fast upsample and fast DCT. PrerequisitesĮxample import cv2 from turbojpeg import TurboJPEG, TJPF_GRAY, TJSAMP_GRAY, TJFLAG_PROGRESSIVE, TJFLAG_FASTUPSAMPLE, TJFLAG_FASTDCT # specifying library path explicitly # jpeg = TurboJPEG(r'D:\turbojpeg.dll') # jpeg = TurboJPEG('/usr/lib64/libturbojpeg.so') # jpeg = TurboJPEG('/usr/local/lib/libturbojpeg.dylib') # using default library installation jpeg = TurboJPEG () # decoding input.jpg to BGR array in_file = open ( 'input.jpg', 'rb' ) bgr_array = jpeg. A Python wrapper of libjpeg-turbo for decoding and encoding JPEG image.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |