4

我使用帶Google的Google App Engine來託管一些後端腳本並將數據存儲在數據存儲中,我需要利用openCV進行一些更高級的媒體操作。Google Cloud VM - 安裝openCV

我想切換到Google Cloud VM平臺,但我無法理解如何安裝openCV。今天

早些時候,在VM雲殼牌我想:

sudo apt-get install python-opencv 

這似乎工作,並列出我的Python模塊後,我得到了:

help> modules 

Please wait a moment while I gather a list of all available modules... 

/usr/local/lib/python2.7/dist-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead. 
    "You should import from ipykernel or jupyter_client instead.", ShimWarning) 
BaseHTTPServer  audiodev   importlib   setuptools 
Bastion    audioop    imputil    sgmllib 
CDROM    autoreload   inspect    sha 
CGIHTTPServer  base64    io     shelve 
Canvas    bdb     ipython_genutils shlex 
ConfigParser  binascii   itertools   shutil 
Cookie    binhex    json    signal 
DLFCN    bisect    keyword    simplegeneric 
Dialog    bsddb    lib2to3    site 
DocXMLRPCServer  bz2     linecache   sitecustomize 
FileDialog   cPickle    linuxaudiodev  six 
FixTk    cProfile   locale    smtpd 
HTMLParser   cStringIO   logging    smtplib 
IN     calendar   macpath    sndhdr 
IPython    cgi     macurl2path   socket 
MimeWriter   cgitb    mailbox    spwd 
Queue    chardet    mailcap    sqlite3 
ScrolledText  chunk    markupbase   sre 
SimpleDialog  cmath    marshal    sre_compile 
SimpleHTTPServer cmd     math    sre_constants 
SimpleXMLRPCServer code    md5     sre_parse 
SocketServer  codecs    meld3    ssl 
StringIO   codeop    mercurial   stat 
TYPES    collections   mhlib    statvfs 
Tix     colorama   mimetools   storemagic 
Tkconstants   colorsys   mimetypes   string 
Tkdnd    commands   mimify    stringold 
Tkinter    compileall   mmap    stringprep 
UserDict   compiler   modulefinder  strop 
UserList   contextlib   multifile   struct 
UserString   cookielib   multiprocessing  subprocess 
_LWPCookieJar  copy    mutex    sunau 
_MozillaCookieJar copy_reg   netrc    sunaudio 
__builtin__   crcmod    new     supervisor 
__future__   crypt    nis     symbol 
_abcoll    csv     nntplib    sympyprinting 
_ast    ctypes    ntpath    symtable 
_bisect    curses    nturl2path   sys 
_bsddb    cv     numbers    sysconfig 
_codecs    cv2     numpy    syslog 
_codecs_cn   cythonmagic   oauth2client  tabnanny 
_codecs_hk   datetime   opcode    tarfile 
_codecs_iso2022  dbhash    operator   telnetlib 
_codecs_jp   dbm     optparse   tempfile 
_codecs_kr   debconf    os     termios 
_codecs_tw   decimal    os2emxpath   test 
_collections  decorator   ossaudiodev   test_path 
_csv    difflib    parser    tests 
_ctypes    dircache   path    textwrap 
_ctypes_test  dis     pdb     this 
_curses    distlib    pexpect    thread 
_curses_panel  distutils   pickle    threading 
_elementtree  doctest    pickleshare   time 
_functools   dumbdbm    pickletools   timeit 
_hashlib   dummy_thread  pip     tkColorChooser 
_heapq    dummy_threading  pipes    tkCommonDialog 
_hotshot   easy_install  pkg_resources  tkFileDialog 
_io     email    pkgutil    tkFont 
_json    encodings   platform   tkMessageBox 
_locale    ensurepip   plistlib   tkSimpleDialog 
_lsprof    errno    popen2    toaiff 
DocXMLRPCServer  bz2     linecache   sitecustomize 
_markerlib   exceptions   poplib    token 
_md5    fcntl    posix    tokenize 
_multibytecodec  filecmp    posixfile   trace 
_multiprocessing fileinput   posixpath   traceback 
_osx_support  fnmatch    pprint    traitlets 
_pyio    formatter   profile    ttk 
_random    fpectl    pstats    tty 
_sha    fpformat   pty     turtle 
_sha256    fractions   ptyprocess   types 
_sha512    ftplib    pwd     unicodedata 
_socket    functools   py_compile   unittest 
_sqlite3   future_builtins  pyasn1    urllib 
_sre    gc     pyasn1_modules  urllib2 
_ssl    genericpath   pyclbr    urllib3 
_strptime   getopt    pydoc    urlparse 
_struct    getpass    pydoc_data   user 
_symtable   gettext    pyexpat    uu 

正如你所看到的,簡歷和列出了cv2。然後我想:

>>> from cv2 import * 

,我也試過:

>>> import cv2 

兩者似乎正確導入模塊。

然而,小時後我試圖重新導入CV2,它沒有被發現,所以我又跑了模塊檢查,並得到:

help> modules 

Please wait a moment while I gather a list of all available modules... 

/usr/local/lib/python2.7/dist-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead. 
    "You should import from ipykernel or jupyter_client instead.", ShimWarning) 
BaseHTTPServer  base64    jinja2    sets 
Bastion    bdb     json    setuptools 
CDROM    binascii   jsonschema   sgmllib 
CGIHTTPServer  binhex    jupyter    sha 
Canvas    bisect    jupyter_client  shelve 
ConfigParser  bsddb    jupyter_console  shlex 
Cookie    bz2     jupyter_core  shutil 
DLFCN    cPickle    keyword    signal 
Dialog    cProfile   lib2to3    simplegeneric 
DocXMLRPCServer  cStringIO   linecache   singledispatch 
FileDialog   calendar   linuxaudiodev  singledispatch_helpers 
FixTk    certifi    locale    site 
HTMLParser   cgi     logging    sitecustomize 
IN     cgitb    macpath    six 
IPython    chardet    macurl2path   smtpd 
MimeWriter   chunk    mailbox    smtplib 
Queue    cmath    mailcap    sndhdr 
ScrolledText  cmd     markupbase   socket 
SimpleDialog  code    markupsafe   spwd 
SimpleHTTPServer codecs    marshal    sqlite3 
SimpleXMLRPCServer codeop    math    sre 
SocketServer  collections   md5     sre_compile 
StringIO   colorama   meld3    sre_constants 
TYPES    colorsys   mercurial   sre_parse 
Tix     commands   mhlib    ssl 
Tkconstants   compileall   mimetools   stat 
Tkdnd    compiler   mimetypes   statvfs 
Tkinter    contextlib   mimify    storemagic 
UserDict   cookielib   mistune    string 
UserList   copy    mmap    stringold 
UserString   copy_reg   modulefinder  stringprep 
_LWPCookieJar  crcmod    multifile   strop 
_MozillaCookieJar crypt    multiprocessing  struct 
__builtin__   csv     mutex    subprocess 
__future__   ctypes    nbconvert   sunau 
_abcoll    curses    nbformat   sunaudio 
_ast    cythonmagic   netrc    supervisor 
_bisect    datetime   new     symbol 
_bsddb    dbhash    nis     sympyprinting 
_codecs    dbm     nntplib    symtable 
_codecs_cn   debconf    notebook   sys 
_codecs_hk   decimal    ntpath    sysconfig 
_codecs_iso2022  decorator   nturl2path   syslog 
_codecs_jp   difflib    numbers    tabnanny 
_codecs_kr   dircache   oauth2client  tarfile 
_codecs_tw   dis     opcode    telnetlib 
_collections  distlib    operator   tempfile 
_csv    distutils   optparse   terminado 
_ctypes    doctest    os     termios 
_ctypes_test  dumbdbm    os2emxpath   test 
_curses    dummy_thread  ossaudiodev   test_path 
_curses_panel  dummy_threading  parser    tests 
_elementtree  easy_install  path    textwrap 
_functools   email    pdb     this 
_hashlib   encodings   pexpect    thread 
_heapq    ensurepip   pickle    threading 
_hotshot   errno    pickleshare   time 
_io     exceptions   pickletools   timeit 
_json    fcntl    pip     tkColorChooser 
_locale    filecmp    pipes    tkCommonDialog 
_lsprof    fileinput   pkg_resources  tkFileDialog 
_markerlib   fnmatch    pkgutil    tkFont 
_md5    formatter   platform   tkMessageBox 
_multibytecodec  fpectl    plistlib   tkSimpleDialog 
_multiprocessing fpformat   popen2    toaiff 
_osx_support  fractions   poplib    token 
_pyio    ftplib    posix    tokenize 
_random    functools   posixfile   tornado 
_sha    functools32   posixpath   trace 
_sha256    future_builtins  pprint    traceback 
_sha512    gc     profile    traitlets 
_socket    genericpath   pstats    ttk 
_sqlite3   getopt    pty     tty 
_sre    getpass    ptyprocess   turtle 
_ssl    gettext    pwd     types 
_strptime   glob    py_compile   unicodedata 
Canvas    bisect    jupyter_client  shelve 
_struct    grp     pyasn1    unittest 
_symtable   gzip    pyasn1_modules  urllib 
_sysconfigdata  hashlib    pyclbr    urllib2 
_sysconfigdata_nd heapq    pydoc    urllib3 
_testcapi   hgext    pydoc_data   urlparse 
_threading_local hmac    pyexpat    user 
_warnings   hotshot    pygments   uu 
_weakref   html5lib   qtconsole   uuid 
_weakrefset   htmlentitydefs  quopri    warnings 
abc     htmllib    random    wave 
aifc    httplib    re     weakref 
antigravity   httplib2   readline   webbrowser 
anydbm    ihooks    repr    whichdb 
argparse   imaplib    requests   wsgiref 
array    imghdr    resource   xdrlib 
ast     imp     rexec    xml 
asynchat   importlib   rfc822    xmllib 
asyncore   imputil    rlcompleter   xmlrpclib 
atexit    inspect    rmagic    xxsubtype 
audiodev   io     robotparser   zipfile 
audioop    ipykernel   rsa     zipimport 
autoreload   ipython_genutils runpy    zlib 
backports   ipywidgets   sched    zmq 
backports_abc  itertools   select    

發生了什麼事我OpenCV的安裝?

如果有人知道如何正確安裝openCV並將其導入到我的python腳本的完整文檔幫助,請發佈該鏈接!我從谷歌雲文檔herehere知道我應該能夠在我的虛擬機上使用openCV。

對於如何設置Dockerfile和requirements.txt文件以正確使用openCV有更詳細的說明也會有幫助。再次,這是在上面鏈接的Google Cloud文檔中引用的,但從未詳細解釋過。

謝謝!

回答

1

Google Cloud Shell只是一個virtual machine運行Google Cloud SDK。這是運行gcloud命令與您的Google雲項目資源進行交互和管理的快捷方式。但它不包含您的實際項目資源。

Cloud Shell的會話僅在活動時持久存在,並且在閒置一小時後終止。因此,在Cloud Shell虛擬機上導入openCV與您的項目完全分離,並且不會以任何方式持久保存。

爲了將您的openCV應用程序部署到App Engine,您需要在openCV應用程序的目錄中使用'gcloud app deploy'命令。

作爲openCV的替代方案,我們現在提供Machine Learning products,它爲應用程序提供了分析圖像,視頻,語音,文本等的能力。

+0

如果安裝在主目錄中,它不會保留嗎? – Lcat

+1

是的,如果您使用[$ HOME目錄](https://cloud.google.com/shell/docs/features#persistent_disk_storage),它將在會話之間保留。儘管如果您不經常訪問雲端Shell,根據文檔,可能會回收$ HOME目錄永久存儲。 – Jordan

+0

@Jordan什麼時間框架正是當你提到'定期'時,沒有提到關於文檔中常規手段的確切時間框架 – Santhosh