# 讀取
)# 灰度變換
gray = cv2.cvtcolor(src,cv2.color_rgb2gray)
# 顯示
cv2.imshow(
"gray"
,gray)
cv2.waitkey(
0)
# 裁剪
src = src[y1:y2,x1:x2]
# 複製
copyimg = src.copy(
)
# 建立mser物件
mser = cv2.mser_create(_min_area=
80,_max_area=
500,_min_diversity=-2
)# 獲取文字區域
'''得到的boxes[i]=[x1,y1,w,h]'''
regions, boxes = mser.detectregions(gray)
# 繪製矩形框
'''注意:給定的座標值必須是整形
img: 所被繪製矩形框的
[startx, starty]: 左上角座標
[endx, endy]:右下角座標
(255,0,0):矩形框的顏色
1: 矩形框的畫素寬度
'''cv2.rectangle(img,
(int
(startx)
,int
(starty)),
(int
(endx)
,int
(endy)),
(255,0
,0),
1)# 繪製圓
cv2.circle(img,
(x, y)
, radius=
5, color=
(255
,255,0
), thickness=-2
)
# 雙邊濾波
dst = cv2.bilateralfilter(gray,10,
10,50)
ret, threshimg = cv2.threshold(dst,0,
255, cv2.thresh_binary | cv2.thresh_********)
# 找輪廓:我這裡扔的是二值化之後的圖
import cv2
showimg = cv2.imread(img_path)
# 讀取
cv2.puttext(showimg,
'text',(
10,20)
, cv2.font_hershey_******x,
0.7,(77
,255,9
),1,cv2.line_aa)
# 新增文字
cv2.imshow(
"result"
,showimg)
# 顯示
cv2.waitkey(
0)
from pil import imagefont, imagedraw, image
showimg = image.
open
(img_path)
# 讀取
draw = imagedraw.draw(showimg)
# 修改
draw.text((10
,20),
'text'
, fill =(77
,255,9
))# 新增文字
showimg.show(
)# 顯示
python opencv常用方法的使用例程
import cv2 cv2.version 3.2.0 import numpy as np 讀取,顯示,寫 cv2.imshow show img 顯示 print np.shape img cv2.waitkey waitkey int delay 0 當delay 0,將無限期的等待下去 當...
整理python opencv常用方法和報錯
沒有讀取到檔案,可能是路徑 檔名 字尾錯了 引數型別錯誤或兩個引數大小不一致,出現在cv2.bitwise and 中,可以.dtype,shape檢視 def cvtcolor src,code,dst none,dstcn none 影象型別轉換,code cv2.color gray2bgr灰...
python常用函式 enumerate函式
1 如果對乙個列表,既要遍歷索引又要遍歷元素時,首先可以這樣寫 list1 這 是 乙個 測試 for i in range len list1 print i list1 i 2 上述方法有些累贅,利用enumerate 會更加直接和優美 list1 這 是 乙個 測試 for index,ite...