程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Face image compression based on Python

編輯:Python

List of articles

    • One 、Windows To configure libjpeg-turbo
      • 1.1、vs2019 Up test jpeg Algorithm
    • Two 、 install PyTurboJPEG library
      • 2.1、 modify PyTurboJPEG Library Configuration
      • 2.2、 install PyTurboJPEG library
    • 3、 ... and 、 Use PyTurboJPEG library

Recently, we have studied image compression methods , Find out JPEG Algorithm decryption This blog , Very well . Intended use python Implement the lower correlation algorithm .

One 、Windows To configure libjpeg-turbo

Reference link :Windows To configure libjpeg-turbo And in python Call in

According to the above link, you can go to windows Top configuration libjpeg-turbo. Here you can have a try .

Here you can refer to the link :windows7 64 On the plane ,libjpeg-turbo Installation and use

1.1、vs2019 Up test jpeg Algorithm

  • Add header file

debugging -> attribute ->c/c++-> routine -> Attach include directory

D:\cplusplus\library\libjpeg-turbo-main
  • Add static library

I cmake The installation directory is install, The path here should be modified according to the actual installation .

debugging -> attribute -> The linker -> routine -> Additional Library Directory ,

D:\cplusplus\library\libjpeg-turbo-main\install\Debug

debugging -> attribute -> The linker -> Input -> Additional dependency

jpeg-static.lib

During the test, you need to install in jconfig.h Copy to the root directory , Otherwise, we will not find . Test code can refer to windows7 64 On the plane ,libjpeg-turbo Installation and use

Two 、 install PyTurboJPEG library

clone Code :https://github.com/lilohuang/PyTurboJPEG.git

2.1、 modify PyTurboJPEG Library Configuration

Add the turbojpeg.dll copy to C:\Windows\System32 Under the table of contents , Secondly, it needs to be modified PyTurboJPEG In the library setup.py file , take 38~50 That's ok :

DEFAULT_LIB_PATHS = {

'Darwin': ['/usr/local/opt/jpeg-turbo/lib/libturbojpeg.dylib'],
'Linux': [
'/usr/lib/x86_64-linux-gnu/libturbojpeg.so.0',
'/usr/lib64/libturbojpeg.so.0',
'/opt/libjpeg-turbo/lib64/libturbojpeg.so'
],
'FreeBSD': [
'/usr/local/lib/libturbojpeg.so.0',
'/usr/local/lib/libturbojpeg.so'
],
'Windows': ['C:/libjpeg-turbo64/bin/turbojpeg.dll']
}

It is amended as follows :

DEFAULT_LIB_PATHS = {

'Darwin': ['/usr/local/opt/jpeg-turbo/lib/libturbojpeg.dylib'],
'Linux': [
'/usr/lib/x86_64-linux-gnu/libturbojpeg.so.0',
'/usr/lib64/libturbojpeg.so.0',
'/opt/libjpeg-turbo/lib64/libturbojpeg.so'
],
'FreeBSD': [
'/usr/local/lib/libturbojpeg.so.0',
'/usr/local/lib/libturbojpeg.so'
],
'Windows': ['turbojpeg.dll']
}

2.2、 install PyTurboJPEG library

cd To install PyTurboJPEG Under the root directory , perform

python setup.py install

3、 ... and 、 Use PyTurboJPEG library

from turbojpeg import TurboJPEG, TJPF_GRAY, TJSAMP_GRAY, TJFLAG_PROGRESSIVE, TJFLAG_FASTUPSAMPLE, TJFLAG_FASTDCT
if __name__ == "__main__":
in_file=open(r"D:\data\face\good3\1630905185050.jpeg","rb")
out_file=open("test.jpg",'wb')
jpeg = TurboJPEG()
img=jpeg.decode(in_file.read())
img=jpeg.encode(img,quality=80)
out_file.write(img)

Windows Next PyTurboJPEG And opencv Compression algorithm speed comparison

FunctionWall-clock timecv2.imdecode()0.358 secTurboJPEG.decode()0.135 seccv2.imencode()0.581 secTurboJPEG.encode()0.140 sec

It can be seen that libjpeg The algorithm speed is better than opencv Its own compression algorithm ...


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved