def readingVideo(videoFile,list_color,classifier,file_name): Color = preprocessing.ColorDetection() File = preprocessing.File() RegionGrowing = preprocessing.RegionGrowing() ImageProcessing = preprocessing.ImageProcessing() Moving = preprocessing.Moving() fireFrame = numpy.array([0,0,0,0]) list_wavelet = [] AllFrame = 0 counter = 0 starts = time.time() while(File.isOpened(videoFile)): try : currentFrame = File.readVideo(videoFile)[1] if len(currentFrame) == 0: return currentFrame2 = copy.copy(currentFrame) currentFrame = ImageProcessing.getDownSize(currentFrame) counter+=1 movingFrame = Moving.getMovingForeGround(copy.copy(currentFrame)) movingPixel = Moving.getMovingCandidatePixel(movingFrame) ColorCandidatePixel = Color.getColorCandidatePixel(copy.copy(movingPixel), copy.copy(currentFrame), list_color) region = RegionGrowing.getRegionGrowing(ColorCandidatePixel[0], copy.copy(currentFrame),list_color,counter) sizeRegionCandidatePixel = RegionGrowing.getFilterSizeRegion(copy.copy(ColorCandidatePixel[0]),copy.copy(region)) grayImage = ImageProcessing.getRGBtoGray(currentFrame2) LL,(HL,LH,HH) = wv.toWavelet(copy.copy(grayImage)) list_wavelet.append([HL,LH,HH]) if (counter<=10): continue list_wavelet.pop(0) FinalCandidatePixel = cls.doClassification(classifier,copy.copy(sizeRegionCandidatePixel[0]),list_wavelet) # fireFrameImage = Moving.markingFire2(FinalCandidatePixel[0],currentFrame) fireFrameImage = ImageProcessing.getUpSize((Moving.markingFire(FinalCandidatePixel[0],currentFrame2, 2))) File.showVideo('Final',fireFrameImage) if len(movingPixel[0])>0: fireFrame[0]+=1 if len(ColorCandidatePixel[0])>0: fireFrame[1]+=1 if len(sizeRegionCandidatePixel[0])>0: fireFrame[2]+=1 if len(FinalCandidatePixel[0])>0: fireFrame[3]+=1 AllFrame+=1 File.waitVideo(1) except : print "Time : ",time.time() - starts return (fireFrame)/float(AllFrame),File.getCountFrame(videoFile),time.time() - starts print "Time : ",time.time() - starts return (fireFrame)/float(AllFrame),File.getCountFrame(videoFile),time.time() - starts
def readingVideo(videoFile): Color = preprocessing.ColorDetection() File = preprocessing.File() RegionGrowing = preprocessing.RegionGrowing() ImageProcessing = preprocessing.ImageProcessing() Moving = preprocessing.Moving() stdDev, mean = Color.getStdDevAndMean('-dataset-fire_image') print "Stdev : "+str(stdDev), "Mean : "+str(mean) print "Video Frame : ",File.getCountFrame(videoFile) print "Video Size : ",len(File.readVideo(videoFile)[1]),len(File.readVideo(videoFile)[1][0]) classifier = cls.getClassifier('-file-datatraining/TA.xls','rbf',5) fireFrame = numpy.array([0,0,0,0]) list_wavelet = [] list_color = Color.getFireArray('-dataset-fire_file/color_5x10^-9.txt') AllFrame = 0 counter = 0 starts = time.time() while(File.isOpened(videoFile)): try : #get curent frame currentFrame = File.readVideo(videoFile)[1] if len(currentFrame) == 0: return currentFrame2 = copy.copy(currentFrame) currentFrame = ImageProcessing.getDownSize(currentFrame) counter+=1 File.saveImage('-code-approving/'+str(counter)+'.png',currentFrame) File.saveImage('-code-approving/'+str(counter)+'_2.png',currentFrame2) # step 1 get moving pixel movingFrame = Moving.getMovingForeGround(copy.copy(currentFrame)) movingPixel = Moving.getMovingCandidatePixel(movingFrame) mvng = mv.getMovingForeGroundColor(currentFrame,movingFrame) File.saveImage('-code-approving/mvng'+str(counter)+'.png',mvng) # step 2 candidate pixel ( color probability ) ColorCandidatePixel = Color.getColorCandidatePixel(copy.copy(movingPixel), copy.copy(currentFrame), list_color) clr = mv.delPixel(ColorCandidatePixel[1], mvng) File.saveImage('-code-approving/clr'+str(counter)+'.png',clr) #region growing region = RegionGrowing.getRegionGrowing(ColorCandidatePixel[0], copy.copy(currentFrame),list_color,counter) reg = copy.copy(currentFrame) for y in range(0,len(region)): for x in range(0,len(region[y])): if region[y][x] == 0: reg[y][x] = [0,0,0] # step 3 region candidate pixel ( region size ) sizeRegionCandidatePixel = RegionGrowing.getFilterSizeRegion(copy.copy(ColorCandidatePixel[0]),copy.copy(region)) siz = mv.delPixel(sizeRegionCandidatePixel[1], clr) File.saveImage('-code-approving/siz'+str(counter)+'.png',siz) #preparing classification grayImage = ImageProcessing.getRGBtoGray(currentFrame2) LL,(HL,LH,HH) = wv.toWavelet(copy.copy(grayImage)) list_wavelet.append([HL,LH,HH]) if (counter<=10): continue list_wavelet.pop(0) FinalCandidatePixel = cls.doClassification(classifier,copy.copy(sizeRegionCandidatePixel[0]),list_wavelet) fireFrameImage = Moving.markingFire(FinalCandidatePixel[0],currentFrame2, 2) fre = mv.delPixel(FinalCandidatePixel[1], siz) File.saveImage('-code-approving/fre'+str(counter)+'.png',fre) # fireFrameImage = Moving.markingFire(FinalCandidatePixel[0],currentFrame) File.showVideo('Final',fireFrameImage) File.saveImage('-code-approving/fnl'+str(counter)+'.png',fireFrameImage) if len(movingPixel[0])>0: fireFrame[0]+=1 if len(ColorCandidatePixel[0])>0: fireFrame[1]+=1 if len(sizeRegionCandidatePixel[0])>0: fireFrame[2]+=1 if len(FinalCandidatePixel[0])>0: fireFrame[3]+=1 AllFrame+=1 File.waitVideo(1) except : print "Time : ",time.time() - starts return (fireFrame)/float(AllFrame) print "Time : ",time.time() - starts return (fireFrame)/float(AllFrame)
def readingVideo(videoFile): Color = preprocessing.ColorDetection() File = preprocessing.File() RegionGrowing = preprocessing.RegionGrowing() ImageProcessing = preprocessing.ImageProcessing() Moving = preprocessing.Moving() stdDev, mean = Color.getStdDevAndMean("-dataset-fire_image") print "Stdev : " + str(stdDev), "Mean : " + str(mean) print "Video Frame : ", File.getCountFrame(videoFile) print "Video Size : ", len(File.readVideo(videoFile)[1]), len(File.readVideo(videoFile)[1][0]) classifier = cls.getClassifier("-file-datatraining/TA.xls", "rbf", 5) fireFrame = numpy.array([0, 0, 0, 0]) list_wavelet = [] list_color = Color.getFireArray("-dataset-fire_file/color_5x10^-9.txt") AllFrame = 0 counter = 0 starts = time.time() while File.isOpened(videoFile): try: # get curent frame currentFrame = File.readVideo(videoFile)[1] if len(currentFrame) == 0: return currentFrame2 = copy.copy(currentFrame) currentFrame = ImageProcessing.getDownSize(currentFrame) counter += 1 # step 1 get moving pixel movingFrame = Moving.getMovingForeGround(copy.copy(currentFrame)) movingPixel = Moving.getMovingCandidatePixel(movingFrame) # step 2 candidate pixel ( color probability ) ColorCandidatePixel = Color.getColorCandidatePixel( copy.copy(movingPixel), copy.copy(currentFrame), list_color ) # region growing region = RegionGrowing.getRegionGrowing( ColorCandidatePixel[0], copy.copy(currentFrame), list_color, counter ) # step 3 region candidate pixel ( region size ) sizeRegionCandidatePixel = RegionGrowing.getFilterSizeRegion( copy.copy(ColorCandidatePixel[0]), copy.copy(region) ) # preparing classification grayImage = ImageProcessing.getRGBtoGray(currentFrame2) LL, (HL, LH, HH) = wv.toWavelet(copy.copy(grayImage)) list_wavelet.append([HL, LH, HH]) if counter <= 10: continue list_wavelet.pop(0) FinalCandidatePixel = cls.doClassification(classifier, copy.copy(sizeRegionCandidatePixel[0]), list_wavelet) fireFrameImage = Moving.markingFire(FinalCandidatePixel[0], currentFrame2, 2) # fireFrameImage = Moving.markingFire2(FinalCandidatePixel[0],currentFrame) File.showVideo("Final", fireFrameImage) if len(movingPixel[0]) > 0: fireFrame[0] += 1 if len(ColorCandidatePixel[0]) > 0: fireFrame[1] += 1 if len(sizeRegionCandidatePixel[0]) > 0: fireFrame[2] += 1 if len(FinalCandidatePixel[0]) > 0: fireFrame[3] += 1 AllFrame += 1 File.waitVideo(1) except: print "Time : ", time.time() - starts return (fireFrame) / float(AllFrame) print "Time : ", time.time() - starts return (fireFrame) / float(AllFrame)
def readingVideo(videoFile): stdDev, mean = pd.getStdDevAndMean('__ChoosenImage2') print "Stdev : "+str(stdDev), "Mean : "+str(mean) print "Video Frame : ",vd.countFrame(videoFile) print "Video Size : ",len(vd.readVideo(videoFile)[1]),len(vd.readVideo(videoFile)[1][0]) counter = 0 cdt = preprocessing.colorDetection() idt = preprocessing.intensityDetection() lum = preprocessing.luminance() grw = preprocessing.growing() classifier = cls.getClassification() fireFrame = numpy.array([0,0,0,0,0,0]) ListWavelet = [] ListLuminance = [] ListGrayImage = [] ListRegion = [] AllFrame = 0 list_color = cdt.retriveColorList() starts = time.time() while(vd.isOpened(videoFile)): try : #get curent frame currentFrame = vd.readVideo(videoFile)[1] #compres image while (len(currentFrame)>150): if (len(currentFrame)<=300): currentFrame2 = copy.copy(currentFrame) currentFrame = vd.downSize(currentFrame) counter+=1 # step 1 get moving pixel movingFrame = mv.getMovingForeGround(vd.copyFile(currentFrame)) movingPixel = mv.getMovingPixel(vd.copyFile(movingFrame)) # step 2 candidate pixel ( color probability ) # ColorCandidatePixel = cdt.getColorCandidatePixel(copy.copy(movingPixel), copy.copy(currentFrame), stdDev, mean) ColorCandidatePixel = cdt.getColorCandidatePixel2(copy.copy(movingPixel), copy.copy(currentFrame), list_color) #region growing # region = grw.getGrowingRegion(ColorCandidatePixel[0], copy.copy(currentFrame),stdDev, mean) region = grw.getGrowingRegion2(ColorCandidatePixel[0], copy.copy(currentFrame),list_color) # step 3 candidate pixel ( brightness ), convert image to gray with luminance and split by region luminanceImageGray = lum.getLuminanceImageGray(copy.copy(currentFrame)) LuminanceCandidatePixel = idt.getLuminanceCandidatePixel(copy.copy(luminanceImageGray),copy.copy(ColorCandidatePixel[0]),copy.copy(region)) # step 4 candidate pixel ( variance color per region ) -- issue on threshold -- VarianceCandidatePixel = grw.getVarianceColorRegion(copy.copy(currentFrame),copy.copy(LuminanceCandidatePixel[0]),copy.copy(region)) #preparing step 5 & 6 grayImage = vd.toGray(currentFrame2) LL,(HL,LH,HH) = wv.toWavelet(copy.copy(grayImage)) luminanceImage = lum.getLumiananceImage(currentFrame) ListLuminance.append(luminanceImage) ListWavelet.append([HL,LH,HH]) ListGrayImage.append(copy.copy(grayImage)) ListRegion.append(region) if (counter<=10): continue ListLuminance.pop(0) ListWavelet.pop(0) ListGrayImage.pop(0) ListRegion.pop(0) DiferenceCandidatePixel = idt.getDiferencePixel(ListLuminance,copy.copy(VarianceCandidatePixel[0])) # RegionCenterMovement = grw.getGrowingCenterPoint(ListRegion,copy.copy(DiferenceCandidatePixel[0])) # DiferenceCandidatePixel = idt.getDiferencePixel2(ListLuminance,copy.copy(DiferenceCandidatePixel[0])) FinalCandidatePixel = cls.doClassification(classifier,copy.copy(DiferenceCandidatePixel[0]),ListWavelet) if len(movingPixel[0])>0: fireFrame[0]+=1 if len(ColorCandidatePixel[0])>0: fireFrame[1]+=1 if len(LuminanceCandidatePixel[0])>0: fireFrame[2]+=1 if len(VarianceCandidatePixel[0])>0: fireFrame[3]+=1 if len(DiferenceCandidatePixel[0])>0: fireFrame[4]+=1 # if len(RegionCenterMovement[0])>0: # fireFrame[5]+=1 if len(FinalCandidatePixel[0])>0: fireFrame[5]+=1 AllFrame+=1 fireFrameImage = vd.upSize(vd.upSize(mv.markPixelRectangle(FinalCandidatePixel[0],currentFrame))) vd.showVideo('Final',fireFrameImage) vd.waitVideo(1) except : print "Time : ",time.time() - starts return (fireFrame)/float(AllFrame) print "Time : ",time.time() - starts return (fireFrame)/float(AllFrame)
def readingVideo(videoFile): stdDev, mean = pd.getStdDevAndMean('__ChoosenImage2') print "Stdev : "+str(stdDev), "Mean : "+str(mean) print "Video Frame : ",vd.countFrame(videoFile) print "Video Size : ",len(vd.readVideo(videoFile)[1]),len(vd.readVideo(videoFile)[1][0]) counter = 0 cdt = preprocessing.colorDetection() idt = preprocessing.intensityDetection() lum = preprocessing.luminance() grw = preprocessing.growing() classifier = cls.getClassification() fireFrame = numpy.array([0,0,0,0,0,0]) ListWavelet = [] ListLuminance = [] ListGrayImage = [] AllFrame = 0 while(vd.isOpened(videoFile)): try : #get curent frame currentFrame = vd.readVideo(videoFile)[1] #compres image while (len(currentFrame)>150): if (len(currentFrame)<=300): currentFrame2 = copy.copy(currentFrame) currentFrame = vd.downSize(currentFrame) # step 1 get moving pixel movingFrame = mv.getMovingForeGround(vd.copyFile(currentFrame)) movingPixel = mv.getMovingPixel(vd.copyFile(movingFrame)) # step 2 candidate pixel ( color probability ) ColorCandidatePixel = cdt.getCandidatePixel(copy.copy(movingPixel), copy.copy(currentFrame), stdDev, mean) # step 3 candidate pixel ( brightness ), convert image to gray with luminance luminanceImageGray = lum.getLuminanceImageGray(copy.copy(currentFrame)) LuminanceCandidatePixel = idt.getIntensityPixel(copy.copy(luminanceImageGray),copy.copy(ColorCandidatePixel[0]),copy.copy(movingPixel)) #convert image to luminance image with gaussian filter 7 and 13 luminanceImage = lum.getLumiananceImage(currentFrame) # covert image to wavelet grayImage = vd.toGray(currentFrame2) LL,(HL,LH,HH) = wv.toWavelet(copy.copy(grayImage)) #step 4 get floodfill ListGrowPixel,avg_region, region = grw.getRegion(LuminanceCandidatePixel[0],copy.copy(currentFrame),stdDev, mean) #append image ListLuminance.append(luminanceImage) ListWavelet.append([HL,LH,HH]) ListGrayImage.append(copy.copy(grayImage)) counter+=1 if (counter<=10): continue ListLuminance.pop(0) ListWavelet.pop(0) ListGrayImage.pop(0) ListDiferrentPixel = idt.getDiferencePixel(ListLuminance,copy.copy(ListGrowPixel[0])) # ListDiferrentPixel = copy.copy(ListGrowPixel) # step 6 FinalCandidatePixel = cls.doClassification(classifier,copy.copy(ListDiferrentPixel[0]),ListWavelet) # cls.doClassification(classifier,copy.copy(ListCandidatePixel[0]),ListWavelet) if len(movingPixel[0])>0: fireFrame[0]+=1 if len(ColorCandidatePixel[0])>0: fireFrame[1]+=1 if len(LuminanceCandidatePixel[0])>0: fireFrame[2]+=1 if len(ListGrowPixel[0])>0: fireFrame[3]+=1 if len(ListDiferrentPixel[0])>0: fireFrame[4]+=1 if len(FinalCandidatePixel[0])>0: fireFrame[5]+=1 AllFrame+=1 fireFrameImage = vd.upSize(vd.upSize(mv.markPixelRectangle(FinalCandidatePixel[0],currentFrame))) vd.showVideo('Final',fireFrameImage) vd.waitVideo(1) except: return (fireFrame)/float(AllFrame) return (fireFrame)/float(AllFrame)
def readingVideo(videoFile, list_color, classes): Color = preprocessing.ColorDetection() File = preprocessing.File() Intensity = preprocessing.Intensity() Luminance = preprocessing.Luminance() RegionGrowing = preprocessing.RegionGrowing() ImageProcessing = preprocessing.ImageProcessing() Moving = preprocessing.Moving() list_wavelet = [] list_luminance = [] list_gray_image = [] list_region = [] counter = 0 feature = [] feature.append(['-','-','-','-','-','-','-','-','-','-']) while(File.isOpened(videoFile)): try : #get curent frame currentFrame = File.readVideo(videoFile)[1] #compres image while (len(currentFrame)>150): if (len(currentFrame)<=300): currentFrame2 = copy.copy(currentFrame) currentFrame = ImageProcessing.getDownSize(currentFrame) counter+=1 gray_image = ImageProcessing.getRGBtoGray(copy.copy(currentFrame)) # step 1 get moving pixel movingFrame = Moving.getMovingForeGround(copy.copy(currentFrame)) movingPixel = Moving.getMovingCandidatePixel(movingFrame) # step 2 candidate pixel ( color probability ) ColorCandidatePixel = Color.getColorCandidatePixel(copy.copy(movingPixel), copy.copy(currentFrame), list_color) #region growing region = RegionGrowing.getRegionGrowing(ColorCandidatePixel[0], copy.copy(currentFrame),list_color,counter) # step 3 candidate pixel ( brightness ), convert image to gray with luminance and split by region luminanceImageGray = Luminance.getLuminanceImageGray(copy.copy(gray_image)) LuminanceCandidatePixel = Intensity.getLuminanceCandidatePixel(copy.copy(luminanceImageGray),copy.copy(ColorCandidatePixel[0]),copy.copy(region)) # step 4 candidate pixel ( variance color per region ) -- issue on threshold -- VarianceCandidatePixel = RegionGrowing.getVarianceColorCandidatePixel(copy.copy(currentFrame),copy.copy(LuminanceCandidatePixel[0]),copy.copy(region)) #preparing step 5 & 6 grayImage = ImageProcessing.getRGBtoGray(currentFrame2) LL,(HL,LH,HH) = wv.toWavelet(copy.copy(grayImage)) luminanceImage = Luminance.getLumiananceImage(copy.copy(gray_image)) list_luminance.append(luminanceImage) list_wavelet.append([HL,LH,HH]) list_gray_image.append(copy.copy(grayImage)) list_region.append(region) if (counter<=10): continue list_luminance.pop(0) list_wavelet.pop(0) list_gray_image.pop(0) list_region.pop(0) DiferenceCandidatePixel = Intensity.getDifferenceCandidatePixel(list_luminance,copy.copy(VarianceCandidatePixel[0])) RegionCenterMovement = RegionGrowing.getMovingPointCandidatePixel2(list_region,copy.copy(DiferenceCandidatePixel[0])) tmp_feature = classification.returnDataTraining(RegionCenterMovement[0],list_wavelet) feature.append(tmp_feature) fireFrameImage = (ImageProcessing.getUpSize(Moving.markingFire(RegionCenterMovement[0],currentFrame2, 2))) File.showVideo('result',fireFrameImage) File.waitVideo(1) except: excel.writeDataTraining('../-file-datatraining/api_TA2.xls',feature,classes) return return