《學(xué)習(xí)OpenCV(中文版)》
作者:(美)布拉德斯基(Bradski隙畜,G.)
(美)克勒(Kaehler别伏,A.) 著
出版社:清華大學(xué)出版社
出版時(shí)間:2009年10月
參考資料:https://blog.csdn.net/hy_z_/article/details/103681088
https://blog.csdn.net/CAI____NIAO/article/details/120734191
一崇败、Cv2.ImRead報(bào)錯(cuò)
- 錯(cuò)誤提示: !_src.empty() in function 'cv::cvtColor'
在運(yùn)行時(shí)報(bào)錯(cuò)菌瘫,根據(jù)顯示熊户,應(yīng)該是沒(méi)有對(duì)cvtColor傳入源圖像途事。
檢查順序:
1验懊、文件路徑正確
2、是絕對(duì)路徑
3尸变、文件名中有中文 - 最后是因?yàn)槲募蛘呶募窂街杏兄形囊逋迹瑢⑻幚砗笪募M(jìn)行保存后發(fā)現(xiàn)英文文件名的圖像正常,而中文錯(cuò)誤召烂。
二碱工、Opencv自帶顏色表操作
namespace CvSharpDemo
{
class Program
{
static void Main(string[] args)
{
ColormapTypes[] color_map = new ColormapTypes[Enum.GetValues(typeof(ColormapTypes)).Length];
int index = 0;
foreach (ColormapTypes temp in Enum.GetValues(typeof(ColormapTypes)))
{
color_map[index] = temp;
index++;
}
index = 0;
Mat src = Cv2.ImRead(@"e:\opencv\bgra.png", ImreadModes.AnyColor);
Cv2.ImShow("src image", src);
int key;
Cv2.NamedWindow("output image", WindowFlags.AutoSize);
Mat output_image = new Mat(src.Size(), src.Type());
while (true)
{
key = Cv2.WaitKey(500);
if (key == 27) break;//跳出while循環(huán)
Cv2.ApplyColorMap(src, output_image, color_map[index % color_map.Length]);
index++;
if (index >= color_map.Length) index = 0;
Cv2.ImShow("outputimage", output_image);
}
Cv2.DestroyAllWindows();
}
}