OpenCV3计算机视觉

  • u1_893588
    了解作者
  • 29.2MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-06 03:17
    上传日期
对于计算机视觉的人来说是一本福利,很值得入手此书。
OpenCV_3_Computer_Vision_with_Python.zip
  • Learning_OpenCV_3_Computer_Vision_with_Python_Second_Edition_Code
  • Chapter 3_Code
  • hough_circles.py
    685B
  • contours_2.py
    1KB
  • contours.py
    413B
  • contours_hull.py
    763B
  • hpf.py
    695B
  • canny.py
    215B
  • skin.py
    1KB
  • fourier.py
    783B
  • hough_lines.py
    405B
  • Chapter 6_Code
  • flann.py
    1.1KB
  • scan_for_matches.py
    1.6KB
  • sift.py
    470B
  • brief.py
    528B
  • generate_descriptors.py
    713B
  • generate_train.py
    829B
  • homography.py
    1.6KB
  • feat_det.py
    701B
  • Chapter 7_Code
  • detect_hog_svm.py
    1.9KB
  • car_detector
  • non_maximum.py
    2.9KB
  • detector.py
    1.9KB
  • __init__.py
    0B
  • sliding_window.py
    215B
  • pyramid.py
    386B
  • car_sliding_windows.py
    1.9KB
  • people_detect_hog.py
    815B
  • Chapter 9_Code
  • digit_recognition.py
    1.9KB
  • simple_ann2.py
    1.1KB
  • animals_ann.py
    3KB
  • images
  • ocr.jpg
    11KB
  • digits.png
    14.4KB
  • numbers.jpg
    188KB
  • MNISTsamples.png
    13.6KB
  • numbers.gif
    3.1KB
  • digits_ann.py
    2.5KB
  • digits_ann.pyc
    3.5KB
  • simple_ann.py
    415B
  • digits_image_process.py
    1.7KB
  • data
  • mnist.pkl.gz
    16.3MB
  • basic_ann.py
    1.2KB
  • Chapter 5_Code
  • disparity.py
    1.7KB
  • disparity_video.py
    1.2KB
  • depth.py
    2.7KB
  • watershed.py
    1007B
  • segmentation.py
    510B
  • Chapter_8_Code
  • camshift.py
    1.1KB
  • lk.py
    1.6KB
  • basic_motion_detection.py
    1KB
  • surveillance_demo
  • output.avi
    5.5KB
  • main.py
    5.6KB
  • traffic.flv
    2.4MB
  • 768x576.avi
    7.8MB
  • kalman_camshift.py
    1.9KB
  • meanshift.jpg
    89.4KB
  • hist.py
    449B
  • .jpg
    78.5KB
  • movie.mpg
    2.7MB
  • knn.py
    1KB
  • mog.py
    964B
  • meanshift.py
    1.3KB
  • kalman.jpg
    65KB
  • kalman.py
    1.5KB
内容介绍
#! /usr/bin/python """Surveillance Demo: Tracking Pedestrians in Camera Feed The application opens a video (could be a camera or a video file) and tracks pedestrians in the video. """ __author__ = "joe minichino" __copyright__ = "property of mankind." __license__ = "MIT" __version__ = "0.0.1" __maintainer__ = "Joe Minichino" __email__ = "joe.minichino@gmail.com" __status__ = "Development" import cv2 import numpy as np import os.path as path import argparse parser = argparse.ArgumentParser() parser.add_argument("-a", "--algorithm", help = "m (or nothing) for meanShift and c for camshift") args = vars(parser.parse_args()) def center(points): """calculates centroid of a given matrix""" x = (points[0][0] + points[1][0] + points[2][0] + points[3][0]) / 4 y = (points[0][1] + points[1][1] + points[2][1] + points[3][1]) / 4 return np.array([np.float32(x), np.float32(y)], np.float32) font = cv2.FONT_HERSHEY_SIMPLEX class Pedestrian(): """Pedestrian class each pedestrian is composed of a ROI, an ID and a Kalman filter so we create a Pedestrian class to hold the object state """ def __init__(self, id, frame, track_window): """init the pedestrian object with track window coordinates""" # set up the roi self.id = int(id) x,y,w,h = track_window self.track_window = track_window self.roi = cv2.cvtColor(frame[y:y+h, x:x+w], cv2.COLOR_BGR2HSV) roi_hist = cv2.calcHist([self.roi], [0], None, [16], [0, 180]) self.roi_hist = cv2.normalize(roi_hist, roi_hist, 0, 255, cv2.NORM_MINMAX) # set up the kalman self.kalman = cv2.KalmanFilter(4,2) self.kalman.measurementMatrix = np.array([[1,0,0,0],[0,1,0,0]],np.float32) self.kalman.transitionMatrix = np.array([[1,0,1,0],[0,1,0,1],[0,0,1,0],[0,0,0,1]],np.float32) self.kalman.processNoiseCov = np.array([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],np.float32) * 0.03 self.measurement = np.array((2,1), np.float32) self.prediction = np.zeros((2,1), np.float32) self.term_crit = ( cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1 ) self.center = None self.update(frame) def __del__(self): print "Pedestrian %d destroyed" % self.id def update(self, frame): # print "updating %d " % self.id hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) back_project = cv2.calcBackProject([hsv],[0], self.roi_hist,[0,180],1) if args.get("algorithm") == "c": ret, self.track_window = cv2.CamShift(back_project, self.track_window, self.term_crit) pts = cv2.boxPoints(ret) pts = np.int0(pts) self.center = center(pts) cv2.polylines(frame,[pts],True, 255,1) if not args.get("algorithm") or args.get("algorithm") == "m": ret, self.track_window = cv2.meanShift(back_project, self.track_window, self.term_crit) x,y,w,h = self.track_window self.center = center([[x,y],[x+w, y],[x,y+h],[x+w, y+h]]) cv2.rectangle(frame, (x,y), (x+w, y+h), (255, 255, 0), 2) self.kalman.correct(self.center) prediction = self.kalman.predict() cv2.circle(frame, (int(prediction[0]), int(prediction[1])), 4, (255, 0, 0), -1) # fake shadow cv2.putText(frame, "ID: %d -> %s" % (self.id, self.center), (11, (self.id + 1) * 25 + 1), font, 0.6, (0, 0, 0), 1, cv2.LINE_AA) # actual info cv2.putText(frame, "ID: %d -> %s" % (self.id, self.center), (10, (self.id + 1) * 25), font, 0.6, (0, 255, 0), 1, cv2.LINE_AA) def main(): # camera = cv2.VideoCapture(path.join(path.dirname(__file__), "traffic.flv")) camera = cv2.VideoCapture(path.join(path.dirname(__file__), "768x576.avi")) # camera = cv2.VideoCapture(path.join(path.dirname(__file__), "..", "movie.mpg")) # camera = cv2.VideoCapture(0) history = 20 # KNN background subtractor bs = cv2.createBackgroundSubtractorKNN() # MOG subtractor # bs = cv2.bgsegm.createBackgroundSubtractorMOG(history = history) # bs.setHistory(history) # GMG # bs = cv2.bgsegm.createBackgroundSubtractorGMG(initializationFrames = history) cv2.namedWindow("surveillance") pedestrians = {} firstFrame = True frames = 0 fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480)) while True: print " -------------------- FRAME %d --------------------" % frames grabbed, frane = camera.read() if (grabbed is False): print "failed to grab frame." break ret, frame = camera.read() fgmask = bs.apply(frame) # this is just to let the background subtractor build a bit of history if frames < history: frames += 1 continue th = cv2.threshold(fgmask.copy(), 127, 255, cv2.THRESH_BINARY)[1] th = cv2.erode(th, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3)), iterations = 2) dilated = cv2.dilate(th, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (8,3)), iterations = 2) image, contours, hier = cv2.findContours(dilated, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) counter = 0 for c in contours: if cv2.contourArea(c) > 500: (x,y,w,h) = cv2.boundingRect(c) cv2.rectangle(frame, (x,y), (x+w, y+h), (0, 255, 0), 1) # only create pedestrians in the first frame, then just follow the ones you have if firstFrame is True: pedestrians[counter] = Pedestrian(counter, frame, (x,y,w,h)) counter += 1 for i, p in pedestrians.iteritems(): p.update(frame) firstFrame = False frames += 1 cv2.imshow("surveillance", frame) out.write(frame) if cv2.waitKey(110) & 0xff == 27: break out.release() camera.release() if __name__ == "__main__": main()
评论
    相关推荐
    • opencv 计算机视觉 编程攻略
      计算机视觉编程攻略 opencv 结构清晰,介绍详细
    • opencv计算机视觉——鼠标响应
      1、OpenCV 2 计算机视觉编程手册_中文版(必学 ) 2、OpenCV 2 Computer.Vision.Application.Programming. 3、OpenCV实例精解(必学) 4、学习OpenCV(中文版) 5、基于OpenCV计算机视觉技术实现 6、深入理解OpenCV...
    • 基于OpenCV计算机视觉技术实现
      《基于OpenCV计算机视觉技术实现》介绍了大约200多个典型的技术问题,覆盖了基于OpenCV基础编程的主要内容,利用大量生动有趣的编程案例和编程技巧,从解决问题和答疑解惑入手,以因特网上最新资料为蓝本,深入浅...
    • 基于OpenCV计算机视觉技术实现
      这是包含《基于OpenCV计算机视觉技术实现》的原书电子版(分章节),和工程代码,资料很全,一般的都是只有代码,没有书,我是把两份集合打包分享给大家。希望对你有帮助。
    • opencv3计算机视觉leaningopcvPracticalIntroduction
      A Practical Introduction to Computer Vision with OpenCV,OpenCV 3计算机视觉 第2版,LearningOpenCV3(第3版)经过大量的筛选,找出三本学习opencv技术最佳图书组合。pdf格式,清晰有目录,打包下载。
    • 基于opencv计算机视觉实现
      是基于opencv计算机视觉实现这本书中的所有源代码
    • OpenCV 2 计算机视觉编程手册
      OpenCV 2 计算机视觉编程手册 源代码
    • 基于OpenCV计算机视觉技术实现
      基于OpenCV计算机视觉技术实现,可以学学,很不错哦,基于OpenCV计算机视觉技术实现,可以学学,很不错哦
    • OpenCV计算机视觉常用测试图
      OpenCV计算机视觉的常用测试图,里面包含baboon、man、monarch、sailboat、soccer、lena、tiffany等!里面还有标准测试图
    • GaussDB_100_1.0.1-DATABASE-REDHAT-64bit.tar.gz
      guassdb100在redhat上安装包,单机部署的包,安装步骤请看我的文中介绍,经过大量实验搭建总结出来的文档