OPENCV图像处理

  • kdx
    了解作者
  • C/C++
    开发工具
  • 3.6KB
    文件大小
  • 7z
    文件格式
  • 0
    收藏次数
  • 5 积分
    下载积分
  • 0
    下载次数
  • 2022-06-28 15:51
    上传日期
如何通过 Python 接口使用流行的计算机视觉库 OpenCV。 OpenCV 是一个C++ 库,用于(实时)处理计算视觉问题。实时处理计算机视觉的 C++ 库,最初由英特尔公司开发,现由 Willow Garage 维护。 OpenCV 是在 BSD 许可下发布的开源库,这意味着它对于学术研究和商业应用是免费的。 OpenCV 2.0 版本对于 Python 的支持已经得到了极大的改善。下面,我们会讲解一些基本的例子并深入了解视频与跟踪。
ch10.7z
  • ch10
  • ch10_P215.py
    393B
  • lktrack.py
    3.7KB
  • ch10_P221_lktrack-bt.py
    332B
  • ch10_P216_optical-flow.py
    1KB
  • ch10_P212_Fig10-2.py
    984B
  • ch10_P211_Displaying-Images-and-Results.py
    980B
  • ch10_P214_01.py
    197B
  • ch10_P214_02.py
    280B
  • ch10_P261_Fig10-3.py
    695B
  • ch10_fig10-6_generator.py
    504B
  • ch10_P217.py
    1009B
  • ch10_P210_readingandWritingImages.py
    264B
内容介绍
from numpy import * import cv2 # some constants and default parameters lk_params = dict(winSize=(15,15),maxLevel=2, criteria=(cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT,10,0.03)) subpix_params = dict(zeroZone=(-1,-1),winSize=(10,10), criteria = (cv2.TERM_CRITERIA_COUNT | cv2.TERM_CRITERIA_EPS,20,0.03)) feature_params = dict(maxCorners=500,qualityLevel=0.01,minDistance=10) class LKTracker(object): """ Class for Lucas-Kanade tracking with pyramidal optical flow.""" def __init__(self,imnames): """ Initialize with a list of image names. """ self.imnames = imnames self.features = [] self.tracks = [] self.current_frame = 0 def step(self,framenbr=None): """ Step to another frame. If no argument is given, step to the next frame. """ if framenbr is None: self.current_frame = (self.current_frame + 1) % len(self.imnames) else: self.current_frame = framenbr % len(self.imnames) def detect_points(self): """ Detect 'good features to track' (corners) in the current frame using sub-pixel accuracy. """ # load the image and create grayscale self.image = cv2.imread(self.imnames[self.current_frame]) self.gray = cv2.cvtColor(self.image,cv2.COLOR_BGR2GRAY) # search for good points features = cv2.goodFeaturesToTrack(self.gray, **feature_params) # refine the corner locations cv2.cornerSubPix(self.gray,features, **subpix_params) self.features = features self.tracks = [[p] for p in features.reshape((-1,2))] self.prev_gray = self.gray def track_points(self): """ Track the detected features. """ if self.features != []: self.step() # move to the next frame # load the image and create grayscale self.image = cv2.imread(self.imnames[self.current_frame]) self.gray = cv2.cvtColor(self.image,cv2.COLOR_BGR2GRAY) # reshape to fit input format tmp = float32(self.features).reshape(-1, 1, 2) # calculate optical flow features,status,track_error = cv2.calcOpticalFlowPyrLK(self.prev_gray,self.gray,tmp,None,**lk_params) # remove points lost self.features = [p for (st,p) in zip(status,features) if st] # clean tracks from lost points features = array(features).reshape((-1,2)) for i,f in enumerate(features): self.tracks[i].append(f) ndx = [i for (i,st) in enumerate(status) if not st] ndx.reverse() #remove from back for i in ndx: self.tracks.pop(i) self.prev_gray = self.gray def track(self): """ Generator for stepping through a sequence.""" for i in range(len(self.imnames)): if self.features == []: self.detect_points() else: self.track_points() # create a copy in RGB f = array(self.features).reshape(-1,2) im = cv2.cvtColor(self.image,cv2.COLOR_BGR2RGB) yield im,f def draw(self): """ Draw the current image with points using OpenCV's own drawing functions. Press ant key to close window.""" # draw points as green circles for point in self.features: cv2.circle(self.image,(int(point[0][0]),int(point[0][1])),3,(0,255,0),-1) cv2.imshow('LKtrack',self.image) cv2.waitKey()
评论
    相关推荐
    • OpenCV
      OpenCV
    • Unbuntu Opencv
      在Linuix下配置Opencv要先对Opencv进行编译,这是用Cmaker已经编译好的文件,可以直接sudo命令用。
    • opencv手册
      opencv手册,详细介绍了opencv的封装函数,内容全面Opencv开发必备!
    • opencv
      opencv
    • OpenCV
      使用opencv和dlib构建基本的Compyter视觉应用程序
    • opencv程序
      OpenCV程序包含双目摄像机标定,棋盘图像矫正,立体像对校正,立体匹配,三维重建模块。然后用OpenGL显示重建效果,并可以通过键盘方向键旋转
    • opencv
      这是一个opencv库。可以让我们方便的使用,拿走不谢。
    • OpenCV
      OpenCV
    • opencv
      OpenCV
    • OpenCV
      OpenCV 特征检测,分类器图像