windows编译tensorflow tensorflow单机多卡程序的框架 tensorflow的操作 tensorflow的变量初始化和scope 人体姿态检测 segmentation标注工具 tensorflow模型恢复与inference的模型简化 利用多线程读取数据加快网络训练 tensorflow使用LSTM pytorch examples 利用tensorboard调参 深度学习中的loss函数汇总 纯C++代码实现的faster rcnn tensorflow使用记录 windows下配置caffe_ssd use ubuntu caffe as libs use windows caffe like opencv windows caffe implement caffe model convert to keras model flappyBird DQN Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Neural Networks Fast-style-transfer tensorflow安装 tensorflow DQN Fully Convolutional Models for Semantic Segmentation Transposed Convolution, Fractionally Strided Convolution or Deconvolution 基于tensorflow的分布式部署 用python实现mlp bp算法 用tensorflow和tflearn搭建经典网络结构 Data Augmentation Tensorflow examples Training Faster RCNN with Online Hard Example Mining 使用Tensorflow做Prisma图像风格迁移 RNN(循环神经网络)推导 深度学习中的稀疏编码思想 利用caffe与lmdb读写图像数据 分析voc2007检测数据 用python写caffe网络配置 ssd开发 将KITTI的数据格式转换为VOC Pascal的xml格式 Faster RCNN 源码分析 在Caffe中建立Python layer 在Caffe中建立C++ layer 为什么CNN反向传播计算梯度时需要将权重旋转180度 Caffe使用教程(下) Caffe使用教程(上) CNN反向传播 Softmax回归 Caffe Ubuntu下环境配置

python小程序

2017年02月04日

python连续帧图片写视频

import cv2,os
dictionary='show'
size = (1280,672)
fps=20
video=cv2.VideoWriter('demo_show.avi', cv2.cv.CV_FOURCC('M','J','P','G'), fps,size)
for i in range(5782):
    name = str(i)+'.jpg'
    im_path = os.path.join('/home/dlg',dictionary,name)
    im = cv2.imread(im_path)
    video.write(im)
print 'done'

python 用opencv检测视频中人脸

import cv2
import os
import sys
 
OUTPUT_DIR = './my_faces'
if not os.path.exists(OUTPUT_DIR):
    os.makedirs(OUTPUT_DIR)
face_haar = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
cam = cv2.VideoCapture(0)
count = 0
while True:
    print(count)
    if count < 10000:
        _, img = cam.read()
	gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
	faces = face_haar.detectMultiScale(gray_image, 1.3, 5)
	for face_x,face_y,face_w,face_h in faces:
	    face = img[face_y:face_y+face_h, face_x:face_x+face_w]
	    face = cv2.resize(face, (64, 64))
	    cv2.imshow('img', face)
	    cv2.imwrite(os.path.join(OUTPUT_DIR, str(count)+'.jpg'), face)
	    count += 1
	key = cv2.waitKey(30) & 0xff
	if key == 27:
            break
    else:
        break

用python requests模块下载数据

import requests
import tarfile
 
url = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz'
save_path = "my_path"
if not os.path.exists(save_path):
	os.makedirs(save_path)
 
filename = "save_file"
filepath = os.path.join(save_path, filename)
# 下载
if not os.path.exists(filepath):
	print("downloading...", filename)
	r = requests.get(url)
	with open(filepath, 'wb') as f:
	    f.write(r.content)
# 解压
tarfile.open(filepath, 'r:gz').extractall(filepath)

python opencv3 跟踪API

import cv2
import sys
 
if __name__ == '__main__' :
 
    # Set up tracker.
    # Instead of MIL, you can also use
    # BOOSTING, KCF, TLD, MEDIANFLOW or GOTURN
     
    tracker = cv2.Tracker_create("MIL")
 
    # Read video
    video = cv2.VideoCapture("1.mp4")
 
    # Exit if video not opened.
    if not video.isOpened():
        print "Could not open video"
        sys.exit()
 
    # Read first frame.
    ok, frame = video.read()
    if not ok:
        print 'Cannot read video file'
        sys.exit()
     
    # Define an initial bounding box
    #bbox = (287, 23, 86, 320)
 
    # Uncomment the line below to select a different bounding box
    bbox = cv2.selectROI(frame, False)
 
    # Initialize tracker with first frame and bounding box
    ok = tracker.init(frame, bbox)
 
    while True:
        # Read a new frame
        ok, frame = video.read()
        if not ok:
            break
         
        # Update tracker
        ok, bbox = tracker.update(frame)
 
        # Draw bounding box
        if ok:
            p1 = (int(bbox[0]), int(bbox[1]))
            p2 = (int(bbox[0] + bbox[2]), int(bbox[1] + bbox[3]))
            cv2.rectangle(frame, p1, p2, (0,0,255))
 
        # Display result
        cv2.imshow("Tracking", frame)
 
        # Exit if ESC pressed
        k = cv2.waitKey(1) & 0xff
        if k == 27 : break

python opencv 画图

#!/usr/bin/env python  
  
import numpy as np  
import cv2  
  
img = np.zeros((512,512,3), np.uint8)  
  
cv2.line(img, (0,0), (511, 511), (255,0,0), 5) #line color (BGR)  
  
cv2.rectangle(img, (384,0), (510, 128), (0, 255, 0), 3)  
  
cv2.circle(img, (447, 63), 63, (0,0,255), -1) #linewidth -1 means fill circle using setted color  
  
cv2.ellipse(img, (256,256), (100,50),45,0,270,(0,0,255),-1) #椭圆的第二个参数是椭圆中心,第三个参数是椭圆长轴和短轴对应的长度,第四个参数45是顺时针旋转45度, 第五个参数是从0度开始,顺时针画270的弧,第七个参数是颜色,最后一个是用颜色填充椭圆内部  
font = cv2.FONT_HERSHEY_SIMPLEX  
cv2.putText(img, 'Hello', (10,500), font, 4, (255,255,255), 2)  
  
cv2.imshow('image', img)  
cv2.waitKey(0)

blog comments powered by Disqus