pythonopencv安裝
可以使用OpenCV,OpenCV的人臉檢測功能在一般場合還是不錯的。而ubuntu正好提供了-opencv這個包,用它可以方便地實現人臉檢測的代碼。
寫代碼之前應該先安裝python-opencv:
#!/usr/bin/python
#-*-coding:UTF-8-*-
#face_detect.py
#FaceDetectionusingOpenCV.Basedonsamplecodefrom:
#http://python.pastebin.com/m76db1d6b
#Usage:pythonface_detect.py<image_file>
importsys,os
fromopencv.cvimport*
fromopencv.highguiimport*
fromPILimportImage,ImageDraw
frommathimportsqrt
defdetectObjects(image):
""""""
grayscale=cvCreateImage(cvSize(image.width,image.height),8,1)
cvCvtColor(image,grayscale,CV_BGR2GRAY)
storage=cvCreateMemStorage(0)
cvClearMemStorage(storage)
cvEqualizeHist(grayscale,grayscale)
cascade=cvLoadHaarClassifierCascade(
'/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml',
cvSize(1,1))
faces=cvHaarDetectObjects(grayscale,cascade,storage,1.1,2,
CV_HAAR_DO_CANNY_PRUNING,cvSize(20,20))
result=[]
forfinfaces:
result.append((f.x,f.y,f.x+f.width,f.y+f.height))
returnresult
defgrayscale(r,g,b):
returnint(r*.3+g*.59+b*.11)
defprocess(infile,outfile):
image=cvLoadImage(infile);
ifimage:
faces=detectObjects(image)
im=Image.open(infile)
iffaces:
draw=ImageDraw.Draw(im)
forfinfaces:
draw.rectangle(f,outline=(255,0,255))
im.save(outfile,"JPEG",quality=100)
else:
print"Error:cannotdetectfaceson%s"%infile
if__name__=="__main__":
process('input.jpg','output.jpg')
Ⅱ linux上安裝python3.4.4,執行./configure的時候報錯,怎麼解決
config.log的內容:
This file contains any messages proced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by python configure 3.4, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ ./configure
## --------- ##
## Platform. ##
## --------- ##
hostname = hbttdb1
uname -m = x86_64
uname -r = 2.6.32-279.el6.x86_64
uname -s = Linux
uname -v = #1 SMP Wed Jun 13 18:24:36 EDT 2012
/usr/bin/uname -p = unknown
/bin/uname -X = unknown
/bin/arch = x86_64
/usr/bin/arch -k = unknown
/usr/convex/getsysinfo = unknown
/usr/bin/hostinfo = unknown
/bin/machine = unknown
/usr/bin/oslevel = unknown
/bin/universe = unknown
PATH: /usr/lib64/qt-3.3/bin
PATH: /usr/local/sbin
PATH: /usr/local/bin
PATH: /sbin
PATH: /bin
PATH: /usr/sbin
PATH: /usr/bin
PATH: /root/bin
PATH: /data/oracle/app/oracle/proct/11.2.0/bin
PATH: .
## ----------- ##
## Core tests. ##
## ----------- ##
configure:2894: checking build system type
configure:2908: result: x86_64-unknown-linux-gnu
configure:2928: checking host system type
configure:2941: result: x86_64-unknown-linux-gnu
configure:3053: checking for --enable-universalsdk
configure:3100: result: no
configure:3123: checking for --with-universal-archs
configure:3138: result: no
configure:3288: checking MACHDEP
configure:3494: result: linux
configure:3518: checking for --without-gcc
configure:3541: result: no
configure:3665: checking for gcc
configure:3681: found /usr/bin/gcc
configure:3692: result: gcc
configure:3921: checking for C compiler version
configure:3930: gcc --version >&5
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for ing conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
configure:3941: $? = 0
configure:3930: gcc -v >&5
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=Red Hat Bugzilla Main Page --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
configure:3941: $? = 0
configure:3930: gcc -V >&5
gcc: '-V' option must have argument
configure:3941: $? = 1
configure:3930: gcc -qversion >&5
gcc: unrecognized option '-qversion'
gcc: no input files
configure:3941: $? = 1
configure:3961: checking whether the C compiler works
configure:3983: gcc conftest.c >&5
configure:3987: $? = 0
configure:4035: result: yes
configure:4038: checking for C compiler default output file name
configure:4040: result: a.out
configure:4046: checking for suffix of executables
configure:4053: gcc -o conftest conftest.c >&5
configure:4057: $? = 0
configure:4079: result:
configure:4101: checking whether we are cross compiling
configure:4109: gcc -o conftest conftest.c >&5
In file included from /usr/include/stdio.h:75,
from conftest.c:11:
/usr/include/libio.h:332: error: expected specifier-qualifier-list before 'size_t'
/usr/include/libio.h:364: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/libio.h:373: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/libio.h:495: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_IO_sgetn'
In file included from conftest.c:11:
/usr/include/stdio.h:318: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:324: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:336: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:343: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:385: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:387: error: format string argument not a string type
/usr/include/stdio.h:389: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:391: error: format string argument not a string type
/usr/include/stdio.h:661: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:664: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:674: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:704: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fread'
/usr/include/stdio.h:710: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fwrite'
/usr/include/stdio.h:732: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fread_unlocked'
/usr/include/stdio.h:734: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fwrite_unlocked'
configure:4113: $? = 1
configure:4120: ./conftest
./configure: line 4122: ./conftest: No such file or directory
configure:4124: $? = 127
configure:4131: error: in `/root/msk/py_workspace/py_setup/Python-3.4.4':
configure:4133: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
## ---------------- ##
## Cache variables. ##
## ---------------- ##
ac_cv_build=x86_64-unknown-linux-gnu
ac_cv_env_CC_set=
ac_cv_env_CC_value=
ac_cv_env_CFLAGS_set=
ac_cv_env_CFLAGS_value=
ac_cv_env_CPPFLAGS_set=
ac_cv_env_CPPFLAGS_value=
ac_cv_env_CPP_set=
ac_cv_env_CPP_value=
ac_cv_env_LDFLAGS_set=
ac_cv_env_LDFLAGS_value=
ac_cv_env_LIBS_set=
ac_cv_env_LIBS_value=
ac_cv_env_MACHDEP_set=
ac_cv_env_MACHDEP_value=
ac_cv_env_PKG_CONFIG_LIBDIR_set=
ac_cv_env_PKG_CONFIG_LIBDIR_value=
ac_cv_env_PKG_CONFIG_PATH_set=
ac_cv_env_PKG_CONFIG_PATH_value=
ac_cv_env_PKG_CONFIG_set=
ac_cv_env_PKG_CONFIG_value=
ac_cv_env_build_alias_set=
ac_cv_env_build_alias_value=
ac_cv_env_host_alias_set=
ac_cv_env_host_alias_value=
ac_cv_env_target_alias_set=
ac_cv_env_target_alias_value=
ac_cv_host=x86_64-unknown-linux-gnu
ac_cv_prog_ac_ct_CC=gcc
## ----------------- ##
## Output variables. ##
## ----------------- ##
ABIFLAGS=''
AR=''
ARCH_RUN_32BIT=''
ARFLAGS=''
ASDLGEN=''
BASECFLAGS=''
BASECPPFLAGS=''
BLDLIBRARY=''
BLDSHARED=''
BUILDEXEEXT=''
CC='gcc'
CCSHARED=''
CFLAGS=''
CFLAGSFORSHARED=''
CFLAGS_NODIST=''
CONFIGURE_MACOSX_DEPLOYMENT_TARGET=''
CONFIG_ARGS=''
CPP=''
CPPFLAGS=''
CXX=''
DEFS=''
DLINCLDIR=''
DLLLIBRARY=''
DYNLOADFILE=''
ECHO_C=''
ECHO_N='-n'
ECHO_T=''
EGREP=''
ENSUREPIP=''
EXEEXT=''
EXPORT_MACOSX_DEPLOYMENT_TARGET='#'
EXT_SUFFIX=''
FRAMEWORKALTINSTALLFIRST=''
FRAMEWORKALTINSTALLLAST=''
FRAMEWORKINSTALLAPPSPREFIX=''
FRAMEWORKINSTALLFIRST=''
FRAMEWORKINSTALLLAST=''
FRAMEWORKPYTHONW=''
FRAMEWORKUNIXTOOLSPREFIX='/usr/local'
GNULD=''
GREP=''
HAS_HG='no-repository'
HAVE_GETHOSTBYNAME=''
HAVE_GETHOSTBYNAME_R=''
HAVE_GETHOSTBYNAME_R_3_ARG=''
HAVE_GETHOSTBYNAME_R_5_ARG=''
HAVE_GETHOSTBYNAME_R_6_ARG=''
HGBRANCH=''
HGTAG=''
HGVERSION=''
INSTALL_DATA=''
INSTALL_PROGRAM=''
INSTALL_SCRIPT=''
INSTSONAME=''
LDCXXSHARED=''
LDFLAGS=''
LDLAST=''
LDLIBRARY=''
LDLIBRARYDIR=''
LDSHARED=''
LDVERSION=''
LIBC=''
LIBFFI_INCLUDEDIR=''
LIBM=''
LIBOBJS=''
LIBPL=''
LIBRARY=''
LIBS=''
LIBTOOL_CRUFT=''
LINKCC=''
LINKFORSHARED=''
LIPO_32BIT_FLAGS=''
LN=''
LTLIBOBJS=''
MACHDEP='linux'
MACHDEP_OBJS=''
MAINCC=''
MKDIR_P=''
MULTIARCH=''
NO_AS_NEEDED=''
OBJEXT=''
OPT=''
OTHER_LIBTOOL_OPT=''
PACKAGE_BUGREPORT='List of issues - Python tracker'
PACKAGE_NAME='python'
PACKAGE_STRING='python 3.4'
PACKAGE_TARNAME='python'
PACKAGE_URL=''
PACKAGE_VERSION='3.4'
PATH_SEPARATOR=':'
PKG_CONFIG=''
PKG_CONFIG_LIBDIR=''
PKG_CONFIG_PATH=''
PLATDIR='plat-linux'
PY3LIBRARY=''
PYTHON=''
PYTHONFRAMEWORK=''
PYTHONFRAMEWORKDIR='no-framework'
PYTHONFRAMEWORKIDENTIFIER='org.python.python'
PYTHONFRAMEWORKINSTALLDIR=''
PYTHONFRAMEWORKPREFIX=''
PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
PY_ENABLE_SHARED=''
RANLIB=''
READELF=''
RUNSHARED=''
SGI_ABI=''
SHELL='/bin/sh'
SHLIBS=''
SHLIB_SUFFIX=''
SIGNAL_OBJS=''
SOABI=''
SOVERSION='1.0'
SRCDIRS=''
TCLTK_INCLUDES=''
TCLTK_LIBS=''
THREADHEADERS=''
THREADOBJ=''
TRUE=''
UNIVERSALSDK=''
UNIVERSAL_ARCH_FLAGS=''
USE_INLINE=''
USE_SIGNAL_MODULE=''
USE_THREAD_MODULE=''
VERSION='3.4'
_PYTHON_HOST_PLATFORM=''
ac_ct_AR=''
ac_ct_CC='gcc'
ac_ct_CXX=''
ac_ct_READELF=''
bindir='${exec_prefix}/bin'
build='x86_64-unknown-linux-gnu'
build_alias=''
build_cpu='x86_64'
build_os='linux-gnu'
build_vendor='unknown'
datadir='${datarootdir}'
datarootdir='${prefix}/share'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
dvidir='${docdir}'
exec_prefix='NONE'
host='x86_64-unknown-linux-gnu'
host_alias=''
host_cpu='x86_64'
host_os='linux-gnu'
host_vendor='unknown'
htmldir='${docdir}'
includedir='${prefix}/include'
infodir='${datarootdir}/info'
libdir='${exec_prefix}/lib'
libexecdir='${exec_prefix}/libexec'
localedir='${datarootdir}/locale'
localstatedir='${prefix}/var'
mandir='${datarootdir}/man'
oldincludedir='/usr/include'
pdfdir='${docdir}'
prefix='NONE'
program_transform_name='s,x,x,'
psdir='${docdir}'
sbindir='${exec_prefix}/sbin'
sharedstatedir='${prefix}/com'
sysconfdir='${prefix}/etc'
target_alias=''
## ----------- ##
## confdefs.h. ##
## ----------- ##
/* confdefs.h */
#define _GNU_SOURCE 1
#define _NETBSD_SOURCE 1
#define __BSD_VISIBLE 1
#define _BSD_TYPES 1
#define _DARWIN_C_SOURCE 1
#define _XOPEN_SOURCE 700
#define _XOPEN_SOURCE_EXTENDED 1
#define _POSIX_C_SOURCE 200809L
configure: exit 1
Ⅲ 這種圖片可以用Python自動識別嗎
Python圖片文本識別使用的工具是PIL和pytesser。因為他們使用到很多的python庫文件,為了避免一個個工具的安裝,建議使用pythonxy
pytesser是OCR開源項目的一個模塊,在Python中導入這個模塊即可將圖片中的文字轉換成文本。pytesser調用了tesseract。當在Python中調用pytesser模塊時,pytesser又用tesseract識別圖片中的文字。pytesser的使用步驟如下:
首先,安裝Python2.7版本,這個版本比較穩定,建議使用這個版本。
其次,安裝pythoncv。
然後,安裝PIL工具,pytesser的使用需要PIL庫的支持。
接著下載pytesser
最後,將pytesser解壓,這個是免安裝的,可以將解壓後的文件cut到Python安裝目錄的Lib\site-packages下直接使用,比如我的安裝目錄是:C:\Python27\Lib\site-packages,同時把這個目錄添加到環境變數之中。
完成以上步驟之後,就可以編寫圖片文本識別的Python腳本了。參考腳本如下:
from pytesser import *
import ImageEnhance
image = Image.open('D:\\workspace\\python\\5.png')
#使用ImageEnhance可以增強圖片的識別率
enhancer = ImageEnhance.Contrast(image)
image_enhancer = enhancer.enhance(4)
print image_to_string(image_enhancer)
tesseract是谷歌的一個對圖片進行識別的開源框架,免費使用,現在已經支持中文,而且識別率非常高,這里簡要來個helloworld級別的認識
下載之後進行安裝,不再演示。
在tesseract目錄下,有個tesseract.exe文件,主要調用這個執行文件,用cmd運行到這個目錄下,在這個目錄下同時放置一張需要識別的圖片,這里是123.jpg
然後運行:tesseract 123.jpg result
會把123.jpg自動識別並轉換為txt文件到result.txt
但是此時中文識別不好
然後找到tessdata目錄,把eng.traineddata替換為chi_sim.traineddata,並且把chi_sim.traineddata重命名為eng.traineddata
ok,現在中文識別基本達到90%以上了
Ⅳ opencv和python下,運行對圖片的讀取程序時出現的問題!!!
1、需要用到其復他模塊制的函數,如:
for i in range(20) #循環次數
image=cv2.imread("D:\picture\%d.jpg"%(i))#路徑自己選擇。
2、可以先升級你的pip,另外看看你的版本是否匹配,包括py版本和32位64位。
3、關於python下使用opencv讀取圖像。首先需要導入opencv包,上面說的那個Ipython並沒有opencv包,所以想使用的請先正確導入opencv包再說,至於怎麼導入,先下載個opencv包,裡面有關於python的opencv包。
以下照片是關於Ipython的運行界面:
Ⅳ ubutun下opencv3.0+python 2.7安裝完畢,打開python需要用什麼命令嗎
步驟一: 安裝依賴. 不管你是用 Python 2.7+ 還是 Python 3+, 你都需要用 apt-get 來安裝 安裝Open CV 所需要的包,庫等依賴.
步驟二: 編譯 Python 2.7+ 版的 Open CV. 如果你准備用 Python 2.7 那麼這一步你肯定要做的, 做完之後呢, 你就可以跳過步驟三, 直奔步驟四.
步驟三: 編譯 Python 3+ 版的 Open CV. 同樣地, 你准備用 Python 3+ 的話, 步驟二是不用做的, 直接從步驟一來到這里.
步驟四: 確認安裝成功. 在你安裝完成之後, 這一步驟就來確認 Open CV是否安裝成功, 能不能正常地工作.
Ⅵ python怎麼安裝opencv
一、openCV介紹
Open Source Computer Vision Library.OpenCV於1999年由Intel建立,如今由Willow Garage提供支持。OpenCV是一個基於BSD許可(開源)發行的跨平台計算機視覺庫,可以運行在Linux、Windows、MacOS操作系統上。它輕量級而且高效——由一系列 C 函數和少量C++類構成,同時提供了Python、Ruby、MATLAB等語言的介面,實現了圖像處理和計算機視覺方面的很多通用演算法。最新版本是3.1 ,2016年1月29日發布。(引自網路openCV)
簡言之,通過openCV可實現計算機圖像、視頻的編輯。廣泛應用於圖像識別、運動跟蹤、機器視覺等領域。
二、環境
本文適用於win7 64位系統 下的Python3.5。python3.5、pip為必備前提。python可在官網下載:https://www.python.org/downloads/windows/,建議使用exe installer,pip會隨之安裝。
環境變數中加入python安裝路徑,我的是 C:\Program Files\Python35\Scripts\;C:\Program Files\Python35\; 注意分號。
三、開搞
一切就緒以後以管理員身份運行cmd或PowerShell。依次輸入以下命令:
pip install --upgrade setuptools
pip install numpy Matplotlib
pip install opencv-python
opencv環境已經整好,就是這么簡單。只需要numpy、Matplotlib、opencv-python三個包,都不大很快就可以下好,如果下載中間出現error或wrong,重新輸入命令即可。
如果多次下載失敗,可以從http://www.lfd.uci.e/~gohlke/pythonlibs/直接下載whl包安裝,安裝whl包依然使用pip
pip install 包的位置(如:C:\download\xxx.whl)
四、測試
寫.py腳本:
#導入cv模塊import cv2 as cv#讀取圖像,支持 bmp、jpg、png、tiff 等常用格式img = cv.imread("D:\python\test.jpg")#創建窗口並顯示圖像cv.namedWindow("Image")
cv.imshow("Image",img)
cv.waitKey(0)#釋放窗口cv2.destroyAllWindows()
運行以上腳本,如果可以顯示出測試的圖像,則環境搭建成功
Ⅶ python代碼運行助手怎麼打開
python代碼運行助手是能在網頁上運行python語言的工具。因為python的運行環境在很多教程里都是用dos的,黑乎乎的界面看的有點簡陋,所以出了這python代碼運行助手,作為ide。
實際上,python代碼運行助手界面只能算及格分,如果要找ide,推薦使用jupyter。jupyter被集成到ANACONDA里,只要安裝了anacoda就能使用了。
回到這個問題:
1、要打開這運行助手首先要下載一個learning.py,如果找不到可以復制如下代碼另存為「learning.py」,編輯器用sublime、或者notepad++。
#!/usr/bin/envpython3
#-*-coding:utf-8-*-
r'''
learning.py
APython3tutorialfromhttp://www.liaoxuefeng.com
Usage:
python3learning.py
'''
importsys
defcheck_version():
v=sys.version_info
ifv.major==3andv.minor>=4:
returnTrue
print('Yourcurrentpythonis%d.%d.PleaseusePython3.4.'%(v.major,v.minor))
returnFalse
ifnotcheck_version():
exit(1)
importos,io,json,subprocess,tempfile
fromurllibimportparse
fromwsgiref.simple_serverimportmake_server
EXEC=sys.executable
PORT=39093
HOST='local.liaoxuefeng.com:%d'%PORT
TEMP=tempfile.mkdtemp(suffix='_py',prefix='learn_python_')
INDEX=0
defmain():
httpd=make_server('127.0.0.1',PORT,application)
print('ReadyforPythoncodeonport%d...'%PORT)
httpd.serve_forever()
defget_name():
globalINDEX
INDEX=INDEX+1
return'test_%d'%INDEX
defwrite_py(name,code):
fpath=os.path.join(TEMP,'%s.py'%name)
withopen(fpath,'w',encoding='utf-8')asf:
f.write(code)
print('Codewroteto:%s'%fpath)
returnfpath
defdecode(s):
try:
returns.decode('utf-8')
exceptUnicodeDecodeError:
returns.decode('gbk')
defapplication(environ,start_response):
host=environ.get('HTTP_HOST')
method=environ.get('REQUEST_METHOD')
path=environ.get('PATH_INFO')
ifmethod=='GET'andpath=='/':
start_response('200OK',[('Content-Type','text/html')])
return[b'<html><head><title>LearningPython</title></head><body><formmethod="post"action="/run"><textareaname="code"style="width:90%;height:600px"></textarea><p><buttontype="submit">Run</button></p></form></body></html>']
ifmethod=='GET'andpath=='/env':
start_response('200OK',[('Content-Type','text/html')])
L=[b'<html><head><title>ENV</title></head><body>']
fork,vinenviron.items():
p='<p>%s=%s'%(k,str(v))
L.append(p.encode('utf-8'))
L.append(b'</html>')
returnL
ifhost!=HOSTormethod!='POST'orpath!='/run'ornotenviron.get('CONTENT_TYPE','').lower().startswith('application/x-www-form-urlencoded'):
start_response('400BadRequest',[('Content-Type','application/json')])
return[b'{"error":"bad_request"}']
s=environ['wsgi.input'].read(int(environ['CONTENT_LENGTH']))
qs=parse.parse_qs(s.decode('utf-8'))
ifnot'code'inqs:
start_response('400BadRequest',[('Content-Type','application/json')])
return[b'{"error":"invalid_params"}']
name=qs['name'][0]if'name'inqselseget_name()
code=qs['code'][0]
headers=[('Content-Type','application/json')]
origin=environ.get('HTTP_ORIGIN','')
iforigin.find('.liaoxuefeng.com')==-1:
start_response('400BadRequest',[('Content-Type','application/json')])
return[b'{"error":"invalid_origin"}']
headers.append(('Access-Control-Allow-Origin',origin))
start_response('200OK',headers)
r=dict()
try:
fpath=write_py(name,code)
print('Execute:%s%s'%(EXEC,fpath))
r['output']=decode(subprocess.check_output([EXEC,fpath],stderr=subprocess.STDOUT,timeout=5))
exceptsubprocess.CalledProcessErrorase:
r=dict(error='Exception',output=decode(e.output))
exceptsubprocess.TimeoutExpiredase:
r=dict(error='Timeout',output='執行超時')
exceptsubprocess.CalledProcessErrorase:
r=dict(error='Error',output='執行錯誤')
print('Executedone.')
return[json.mps(r).encode('utf-8')]
if__name__=='__main__':
main()
2,再用一個記事本寫如下的代碼:
@echooff
pythonlearning.py
pause
另存為『運行.bat』
3、把「運行.bat」和「learning.py」放到同一目錄下,
Ⅷ python 怎樣安裝open cv
在官網自行下載,這里下載的是opencv2.4.10安裝。
復制cv2.pyd 將」\opencv\build\python\2.7\x64」或」\opencv\build\python\2.7\x86」(根據python版本)文件夾中找到cv2.pyd」,復制到Python安裝文件的」C:\Python27\Lib\site-packages」文件夾中。
Ⅸ 我的python opencv2不知道出錯在哪裡
我沒用過Python的Opencv的庫,只是用過Python的Image的庫;Image庫已經可以結果這個問題了我試著做一下:你先得安裝PIL庫得到rgb三個通道,然後轉到HSV通道,其中H表示0-255的顏色,V表示強度,你大概先知道紫色的范圍是多少from PIL import Imageimport colorsysdef CalculateH(img): if len(img.getbands()) == 4: ir,ig,ib,ia = img.split() else: ir, ig, ib = img.split() Hdat = [] Sdat = [] Vdat = [] for rd,gn,bl in zip(ir.getdata(),ig.getdata(),ib.getdata()): h,l,s = colorsys.rgb_to_hsv(rd/255.,gn/255.,bl/255.) Hdat.append(h) Sdat.append(l) Vdat.append(s) meanV = mean(Vdat) return Hdat, meanV def myreadim(filename): im = Image.open(filename) H,V = CalculateH(im)後面我就懶得寫了,應該思路都清楚了吧,要轉到其他的顏色通道上,不要在rgb通道上