close

前幾天剛安裝OpenCV for Python, 今天準備測試時發生錯誤訊息

import cv2
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-72fbbcfe2587> in <module>()
----> 1 import cv2
 
ImportError: DLL load failed: 找不到指定的程序。


上網google到這一篇[1]看起來跟我的狀況很類似,

學習新工具建立環境總是會遇到一些奇奇怪怪的狀況, 真是考驗人的耐心….

-----------------------------------------------------------

下載並解壓縮OpenCV2.4.13

image_thumb9

開啟C:\OpenCV\OpenCV2.4.13\opencv\build\python\2.7\x86

複製cv2.pyd

image_thumb8

貼上cv2.pyd

image_thumb6

新增系統變數OpenCV2413

image_thumb1[1]

開啟Path系統變數, 然後<新增>%OpenCV2413%

image_thumb3

 
import cv2
 
img = cv2.imread("C:\OpenCV\images\lena.jpg")
 
cv2.namedWindow("fig")
 
cv2.imshow("fig", img)
 
cv2.waitKey(0)

image_thumb12

 
img[:].shape
Out[18]: (512, 512, 3)
 
img[:].strides
Out[21]: (1536, 3, 1)
 
img
Out[24]: 
array([[[128, 138, 225],
        [127, 137, 224],
        [126, 136, 224],
        ..., 
        [126, 145, 236],
        [110, 129, 220],
        [ 86, 104, 197]],
 
       [[127, 137, 224],
        [127, 137, 224],
        [127, 137, 224],
        ..., 
        [130, 150, 235],
        [112, 132, 217],
        [ 83, 102, 189]],
 
       [[127, 137, 224],
        [127, 137, 224],
        [128, 138, 225],
        ..., 
        [127, 148, 230],
        [112, 133, 215],
        [ 85, 105, 190]],
 
       ..., 
       [[ 55,  21,  82],
        [ 54,  20,  81],
        [ 62,  28,  92],
        ..., 
        [ 82,  71, 175],
        [ 78,  68, 175],
        [ 74,  65, 175]],
 
       [[ 55,  18,  80],
        [ 56,  19,  81],
        [ 66,  32,  96],
        ..., 
        [ 82,  69, 177],
        [ 80,  71, 181],
        [ 81,  72, 183]],
 
       [[ 56,  19,  81],
        [ 58,  21,  83],
        [ 68,  34,  98],
        ..., 
        [ 81,  68, 176],
        [ 81,  72, 183],
        [ 84,  74, 188]]], dtype=uint8)
 

顯示type

type(img)
Out[16]: numpy.ndarray

彩色轉灰階

 
imgGray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

image_thumb2


轉黑白


image_thumb1











參考資料:

1. ImportError: DLL load failed: %1 is not a valid Win32 application. But the DLL's are there

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()