资源简介
python版本的GrabCut前景分割和分水岭分割,同时也有深度估计
代码片段和文件信息
import cv2
import numpy as np
from matplotlib import pyplot as plt
def to_uint8( data ) :
# maximum pixel
latch = np.zeros_like( data )
latch[:] = 255
# minimum pixel
zeros = np.zeros_like( data )
# unrolled to illustrate steps
d = np.maximum( zeros data )
d = np.minimum( latch d )
# cast to uint8
return np.asarray( d dtype=“uint8“ )
def drawlines(img1img2linespts1pts2):
‘‘‘ img1 - image on which we draw the epilines for the points in img2
lines - corresponding epilines ‘‘‘
print img1.shape
rc ch = img1.shape
clr1 = cv2.pyrDown(cv2.imread(‘./images/stacked1.png‘ 0))
clr2 = cv2.pyrDown(cv2.imread(‘./images/stacked2.png‘ 0))
for rpt1pt2 in zip(linespts1pts2):
color = tuple(np.random.randint(02553).tolist())
x0y0 = map(int [0 -r[2]/r[1] ])
x1y1 = map(int [c -(r[2]+r[0]*c)/r[1] ])
clr1 = cv2.line(clr1 (x0y0) (x1y1) color1)
clr1 = cv2.circle(clr1tuple(pt1)5color-1)
clr2 = cv2.circle(clr2tuple(pt2)5color-1)
return clr1 clr2
img1 = to_uint8(cv2.pyrDown(cv2.imread(‘./images/stacked1.png‘ cv2.COLOR_BGR2GRAY))) #queryimage # left image
img2 = to_uint8(cv2.pyrDown(cv2.imread(‘./images/stacked2.png‘ cv2.COLOR_BGR2GRAY))) #trainimage # right image
sift = cv2.xfeatures2d.SIFT_create()
# find the keypoints and descriptors with SIFT
kp1 des1 = sift.detectAndCompute(img1None)
kp2 des2 = sift.detectAndCompute(img2None)
# FLANN parameters
FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE trees = 5)
search_params = dict(checks=50)
flann = cv2.FlannbasedMatcher(index_paramssearch_params)
matches = flann.knnMatch(des1des2k=2)
good = []
pts1 = []
pts2 = []
# ratio test as per Lowe‘s paper
for i(mn) in enumerate(matches):
if m.distance < 0.8*n.distance:
good.append(m)
pts2.append(kp2[m.trainIdx].pt)
pts1.append(kp1[m.queryIdx].pt)
pts1 = np.int32(pts1)
pts2 = np.int32(pts2)
F mask = cv2.findFundamentalMat(pts1pts2cv2.FM_LMEDS)
# We select only inlier points
pts1 = pts1[mask.ravel()==1]
pts2 = pts2[mask.ravel()==1]
# Find epilines corresponding to points in right image (second image) and
# drawing its lines on left image
lines1 = cv2.computeCorrespondEpilines(pts2.reshape(-112) 2F)
lines1 = lines1.reshape(-13)
img5img6 = drawlines(img1img2lines1pts1pts2)
# Find epilines corresponding to points in left image (first image) and
# drawing its lines on right image
lines2 = cv2.computeCorrespondEpilines(pts1.reshape(-112) 1F)
lines2 = lines2.reshape(-13)
img3img4 = drawlines(img2img1lines2pts2pts1)
plt.subplot(121)plt.imshow(img5)
plt.subplot(122)plt.imshow(img3)
plt.show()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2737 2016-11-15 15:49 分割\depth.py
文件 1229 2016-11-15 15:49 分割\disparity_video.py
文件 669 2016-11-15 15:49 分割\grabcut.py
文件 487 2016-11-15 15:49 分割\segmentation.py
文件 1007 2016-11-15 15:49 分割\watershed.py
目录 0 2018-06-09 10:45 分割\
- 上一篇:python抓取360百科词条
- 下一篇:Python3实现的用户管理系统
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论