參考鏈接:Windows 配置libjpeg-turbo並在python中調用
根據上述鏈接可以在windows上配置好libjpeg-turbo。這裡可以小試一下。
這裡可以參考鏈接:windows7 64位機上,libjpeg-turbo的安裝和使用
調試->屬性->c/c++->常規->附加包含目錄
D:\cplusplus\library\libjpeg-turbo-main
我cmake時安裝的目錄是install,這裡路徑要根據實際安裝來修改。
調試->屬性->鏈接器->常規->附加庫目錄
,
D:\cplusplus\library\libjpeg-turbo-main\install\Debug
調試->屬性->鏈接器->輸入->附加依賴項
jpeg-static.lib
在測試時需要將install中jconfig.h
拷貝到根目錄下,否則會找不到。測試代碼可以參考windows7 64位機上,libjpeg-turbo的安裝和使用
clone代碼:https://github.com/lilohuang/PyTurboJPEG.git
將第一步中生成的turbojpeg.dll
拷貝到C:\Windows\System32
目錄下,其次還需要修改PyTurboJPEG庫中的setup.py
文件,將38~50行:
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']
}
修改為:
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']
}
cd
到安裝PyTurboJPEG庫根目錄下,執行
python setup.py install
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下PyTurboJPEG與opencv壓縮算法的速度比較
可以看出libjpeg算法速度還是優於opencv自帶的壓縮算法的。。。