2014-01-15 2500 views
1

需要對圖像的顏色通道應用一些快速轉換。Python Opencv cv2.LUT()如何使用

1)我已存儲在一個列表中的對應的輸出值:

ListaVred = [0]*255 

for i in range(0,255): 
    ListaVred[i]=i*127/255 + 128 

2)I從圖像獲得從0色彩輸入值,以255

3)應當在圖像中替換與輸出輸入值

i.e. red[45]= 0 
    ListaVred0] = 128 
    red[45]= 128 

我已經看了cv2.LUT(SRC,DST)功能,但不知道它的使用, http://docs.opencv.org/trunk/modules/core/doc/operations_on_arrays.html#cv2.LUT

cv2.LUT(ListaVred,red) 
TypeError: src is not a numpy array, neither a scalar 


ListaVred = np.array(ListaVred) 
cv2.LUT(ListaVred,red) 
cv2.error: /build/opencv-Ai8DTy/opencv-2.4.6.1+dfsg/modules/core/src/convert.cpp:1195: error: (-215) (lutcn == cn || lutcn == 1) && lut.total() == 256 && lut.isContinuous() && (src.depth() == CV_8U || src.depth() == CV_8S) in function LUT 

回答

2

您查看了尚未發佈的OpenCV版本(3.0版)的文檔。我猜你正在使用OpenCV 2.4.8或更低版本。檢查this documentation。注意LUT函數使用的差異。在頁面頂部,您將看到本文檔所屬的OpenCV版本。

LUT(srcImage, lookupTable, dstImage) 
+0

我在raspbian和OpenCV的版本是2.3.1-11,感謝您的文檔,LUT(紅色,ListaVred,newredlist),但我不能讓如何構建LookupTable中名單,是不是ListaVred格式正確嗎? – user2239318

+0

lookupTable = 256個元素,ListaVred = [0] * 256,而不是255!像魅力一樣工作! – user2239318

相關問題