• 大小: 15KB
    文件类型: .py
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: Python
  • 标签: 烟雾检测  

资源简介

此代码为基于视频的烟雾检测,先预处理,再送入卷积网络训练,检测效果还不错

资源截图

代码片段和文件信息

#coding:utf-8 

from __future__ import print_function
import cv2
import numpy as np 
import tensorflow as tf 
import os
import random
from skimage import io
from skimage import filters
from matplotlib import pyplot as pltssss

__author__ = ‘cystone@aliyun.com‘
__date__ = ‘16-12-19‘

DEBUG = False
AVERAGE_S_THRESHOLD = 70
HSV_V_BLOCK_COUNT = 50
CANDIDATE_BLOCK_SIZE = 10
VIDEO_FILE = “/home/swl/blog/exp_data/code/medias/videos/nosmoke3.avi“
BLOCK_WIDTH = 32
BLOCK_HEIGHT = 24
frame_SKIP = 1
frame_SIZE = (0 0)

train_smoke_path = “/home/swl/blog/exp_data/code/medias/pictures/smoke_train_32x24/“
train_none_path = “/home/swl/blog/exp_data/code/medias/pictures/nosmoke_train_32x24/“
test_smoke_path = “/home/swl/blog/exp_data/code/medias/pictures/smoke_test_32x24/“
test_none_path = “/home/swl/blog/exp_data/code/medias/pictures/nosmoke_test_32x24/“
#test_smoke_path = “/home/swl/blog/exp_data/code/medias/videos/“
#test_none_path = “/home/swl/blog/exp_data/code/medias/videos/“


def get_move_toward(list_frames m n):
    “““
    Get the direction of the area moving towards.
    list_frames is the list of current and last gray frame
    “““
    
    bias = 2

    if mframe_SIZE[0]-BLOCK_WIDTH-bias or n>frame_SIZE[1]-BLOCK_HEIGHT-bias:
        return 7;
    block = list_frames[1][n:(n+BLOCK_HEIGHT) m:(m+BLOCK_WIDTH)]
    block1 = list_frames[0][(n-bias):(n+BLOCK_HEIGHT-bias) m:(m+BLOCK_WIDTH)]
    block2 = list_frames[0][(n-bias):(n+BLOCK_HEIGHT-bias) (m+bias):(m+BLOCK_WIDTH+bias)]
    block3 = list_frames[0][n:(n+BLOCK_HEIGHT) (m+bias):(m+BLOCK_WIDTH+bias)]
    block4 = list_frames[0][(n+bias):(n+BLOCK_HEIGHT+bias) (m+bias):(m+BLOCK_WIDTH+bias)]
    block5 = list_frames[0][(n+bias):(n+BLOCK_HEIGHT+bias) m:(m+BLOCK_WIDTH)]
    block6 = list_frames[0][(n+bias):(n+BLOCK_HEIGHT+bias) (m-bias):(m+BLOCK_WIDTH-bias)]
    block7 = list_frames[0][(n):(n+BLOCK_HEIGHT) (m-bias):(m+BLOCK_WIDTH-bias)]        
    block8 = list_frames[0][(n-bias):(n+BLOCK_HEIGHT-bias) (m-bias):(m+BLOCK_WIDTH-bias)]

    list_result = []
    r1 = calc_direction(block block1)
    list_result.append(r1)
    r2 = calc_direction(block block2)
    list_result.append(r2)
    r3 = calc_direction(block block3)
    list_result.append(r3)
    r4 = calc_direction(block block4)
    list_result.append(r4)
    r5 = calc_direction(block block5)
    list_result.append(r5)
    r6 = calc_direction(block block6)
    list_result.append(r6)
    r7 = calc_direction(block block7)
    list_result.append(r7)
    r8 = calc_direction(block block8)
    list_result.append(r8)
    index = list_result.index(min(list_result))
    return index


def load_images(path):
    “““
    load images from directory
    return a list of images data
    “““
    img_list = []
    for dirpath dirnames filenames in os.walk(path):
        for filename in filenames:
            img = io.imread(path + filename)
            img2 = filters.gaussian(img sigma=1)
            #img2 = color.rgb2hsv(img)

评论

共有 条评论

相关资源