Last active
November 7, 2018 07:59
-
-
Save Roger8/266bd516fb667ae56d7949e33a69e8e9 to your computer and use it in GitHub Desktop.
【opencv】
- 【opencv】中getPerspectiveTransform()函数选择初始区域的四个点和结束区域的四个点的顺序必须是:左上、右上、左下、右下
- java 中Size(width, height) ,分别 对应Mat中的width->Mat.cols() , height->Mat.rows(), 与numpy 中的shape 相反
java/android 中使用注意
- Utils.matToBitmap( mat, bmp) 函数
* @param mat is a valid input Mat object of types 'CV_8UC1', 'CV_8UC3' or 'CV_8UC4'.
* @param bmp is a valid Bitmap object of the same size as the Mat and of type 'ARGB_8888' or 'RGB_565'.
idregionMat.convertTo(idregionMat, CvType.CV_8UC1);
Utils.matToBitmap(idregionMat , gBitmap);//
求文字区域旋转角度后扭正
# grab the (x, y) coordinates of all pixel values that
# are greater than zero, then use these coordinates to
# compute a rotated bounding box that contains all
# coordinates
coords = np.column_stack(np.where(thresh > 0))
angle = cv2.minAreaRect(coords)[-1]
# the `cv2.minAreaRect` function returns values in the
# range [-90, 0); as the rectangle rotates clockwise the
# returned angle trends to 0 -- in this special case we
# need to add 90 degrees to the angle
if angle < -45:
angle = -(90 + angle)
# otherwise, just take the inverse of the angle to make
# it positive
else:
angle = -angle
# rotate the image to deskew it
(h, w) = image.shape[:2]
center = (w // 2, h // 2)
M = cv2.getRotationMatrix2D(center, angle, 1.0)
rotated = cv2.warpAffine(image, M, (w, h),
flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE)
写视频
import cv2
import os
#图片路径
im_dir = '/home/suanfa/data/out/201708231503440'
#输出视频路径
video_dir = '/home/suanfa/data/out/201708231503440-1018.avi'
#帧率
fps = 30
#图片数
num = 426
#图片尺寸
img_size = (841,1023)
#fourcc = cv2.cv.CV_FOURCC('M','J','P','G')#opencv2.4
fourcc = cv2.VideoWriter_fourcc('M','J','P','G') #opencv3.0
videoWriter = cv2.VideoWriter(video_dir, fourcc, fps, img_size)
for i in range(1,num):
im_name = os.path.join(im_dir, str(i).zfill(6)+'.jpg')
frame = cv2.imread(im_name)
videoWriter.write(frame)
print im_name
videoWriter.release()
print 'finish'
读视频 获取视频参数:帧数, 宽/高,fps
cap = cv2.VideoCapture('MOT16-07.mp4')
# 帧数
cap.get(cv2.CAP_PROP_FRAME_COUNT)
# fps
cap.get(cv2.CAP_PROP_FPS)
# 以帧为单位的当前位置
cap.get(cv2.CAP_PROP_POS_FRAMES)
# 跳到指定帧
# jump to specific frame
framestart = 150
cap.set(cv2.CAP_PROP_POS_FRAMES, int(framestart))
ret ,frm= cap.read()
# 宽/高
cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
cap.get(cv2.CAP_PROP_FRAME_WIDTH)
# 编码方式
codec = int(cap.get(cv2.CAP_PROP_FOURCC)) # 828601953
chr(codec&0xFF) + chr((codec>>8)&0xFF) + chr((codec>>16)&0xFF) + chr((codec>>24)&0xFF) # 转换为字符 avc1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
erode, dilate
腐蚀
在数学形态学运算中的作用是消除边界点,使边界向内部收缩
膨胀
将与物体接触的所有背景点合并到该物体中,使边界向外部扩张
开运算(Opening Operation)
先腐蚀后膨胀的过程:(可以用来消除小物体、在纤细点处分离物体、平滑较大物体的边界的同时并不明显改变其面积)
闭运算(Closing Operation)
先膨胀后腐蚀的过程: ( 能够排除小型黑洞(黑色区域)
形态学梯度(Morphological Gradient)
为膨胀图与腐蚀图之差: 可以将团块(blob)的边缘突出出来, 可以用形态学梯度来保留物体的边缘轮廓
顶帽运算(Top Hat)
为原图像与“开运算“的结果图之差: 因为开运算带来的结果是放大了裂缝或者局部低亮度的区域,因此,从原图中减去开运算后的图,得到的效果图突出了比原图轮廓周围的区域更明亮的区域,且这一操作和选择的核的大小相关 。 往往用来分离比邻近点亮一些的斑块。当一幅图像具有大幅的背景的时候,而微小物品比较有规律的情况下,可以使用顶帽运算进行背景提取。
黑帽(Black Hat)
为”闭运算“的结果图与原图像之差: 突出了比原图轮廓周围的区域更暗的区域,且这一操作和选择的核的大小相关。所以,黑帽运算用来分离比邻近点暗一些的斑块