def showSegROI(): cv2.destroyAllWindows() cap = cv2.VideoCapture(r'H:\human_dataset\3_shenle.avi') ii = 0 while True: ret, frame = cap.read() ii += 1 grayim = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) if ret == False: break cv2.imshow('origin', frame) cv2.waitKey(10) ceterframe = frame[105:105 + 300, 104:104 + 512] cetergrayim = grayim[105:105 + 300, 104:104 + 512] threshimg, segrois = roiextract.segmetation_roi(ceterframe) # dimg = cv2.adaptiveThreshold(src = graim,maxValue = 255, adaptiveMethod = cv2.ADAPTIVE_THRESH_GAUSSIAN_C,thresholdType = cv2.THRESH_BINARY_INV,blockSize = 5,C = 3) # dimg = doDualThreshold()#statrow = 105,statcol = 104 # labelrois = labelConnectedComponent(dimg) # for roi in segrois: # hog.svmPredict(cetergrayim,roi) Visual.showResult(cetergrayim, segrois, winname='seg', color=200) #color值越大越线条越偏白 if cv2.waitKey(1) == 32: print('space') while True: if (cv2.waitKey(1) == 32): break cv2.destroyAllWindows()
def segDetect(): cv2.destroyAllWindows() cap = cv2.VideoCapture(r'H:\human_dataset\3_shenle.avi') ii = 0 while True: ret, frame = cap.read() ii += 1 grayim = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) if ret == False: break cv2.imshow('origin', frame) cv2.waitKey(10) ceterframe = frame[105:105 + 300, 104:104 + 512] cetergrayim = grayim[105:105 + 300, 104:104 + 512] threshimg, segrois = roiextract.segmetation_roi(ceterframe) personroi = [] filteredrois = roifilter.getFilteredROI(segrois) print(len(filteredrois)) for roi in filteredrois: if hogsvm.svmPredict(cetergrayim, roi) == 1: personroi.append(roi) print('person') Visual.showResult(threshimg, segrois, winname='seg roi', color=200) #color值越大越线条越偏白 # for roi in segrois: # hog.svmPredict(cetergrayim,roi) Visual.showResult(cetergrayim, personroi, winname='person roi', color=200) #color值越大越线条越偏白 if cv2.waitKey(1) == 32: print('space') while True: if (cv2.waitKey(1) == 32): break cv2.destroyAllWindows()
def showSURFROI(): cv2.destroyAllWindows() cap = cv2.VideoCapture(r'H:\human_dataset\3_shenle.avi') ii = 0 while True: ret, frame = cap.read() ii += 1 grayim = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) if ret == False: break cv2.imshow('origin', frame) cv2.waitKey(10) ceterframe = frame[105:105 + 300, 104:104 + 512] cetergrayim = grayim[105:105 + 300, 104:104 + 512] filteredkps, surfrois = roiextract.surf_roi(cetergrayim, 512, 300) kpimg = cv2.drawKeypoints(ceterframe, filteredkps, None, (255, 0, 0), 4) cv2.imshow('surf keypoint', kpimg) cv2.waitKey(10) # for roi in segrois: # hog.svmPredict(cetergrayim,roi) Visual.showResult(cetergrayim, surfrois, winname='surf', color=200) #color值越大越线条越偏白 if cv2.waitKey(1) == 32: print('space') while True: if (cv2.waitKey(1) == 32): break cv2.destroyAllWindows()
def kpAnnShow(): kpsinfos = parseAllKPFile()#解析所有kp文件 anninfos = parse_all_ann_filtered()#解析所有标注 videopathes = getVideoPath()#读取所有视频路径 for setnum in range(len(videopathes)):#处理所有set for vpath in videopathes[setnum]:#处理set中所有特征点文件 indrs = vpath.rfind('\\') indp = vpath.rfind('.') vstr = vpath[indrs+2:indp]#获取去掉"V"和后缀的视频名 cap = cv2.VideoCapture(vpath) frameindex = 0 vkey = '%02d'%(setnum)+vstr anninfo = anninfos[vkey] kpsinfo = kpsinfos[vkey] while True: frameindex +=1 ret,frame = cap.read() if ret == False:break #kpskey = '%05d'%(frameindex) framekey = vkey+'%05d'%(frameindex) kps = kpsinfo[framekey] ann = anninfo[framekey] ceterframe = frame[105:105 + 300,104:104 + 512] threshimg,segrois = roiextract.segmetation_roi(ceterframe) kprois = cKPS2ROIs(kps) Visual.showResult(ceterframe,ann,'annotation',(255,0,0)) Visual.showResult(ceterframe,kprois,'surf_roi',(0,0,255)) Visual.showResult(ceterframe,segrois,winname = 'seg',color = 200)#color值越大越线条越偏白 # cv2.waitKey(50) return None
def surfDetect(outPath=None): if outPath != None: #将结果写出到视频 fps = 25 #视频帧率 fourcc = cv2.VideoWriter_fourcc('X', 'V', 'I', 'D') videoWriter = cv2.VideoWriter(outPath, fourcc, fps, (768, 576)) #(1360,480)为视频大小 cv2.destroyAllWindows() cap = cv2.VideoCapture(r'H:\human_dataset\3_shenle.avi') ii = 0 while True: ret, frame = cap.read() ii += 1 grayim = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) if ret == False: break cv2.imshow('origin', frame) cv2.waitKey(10) ceterframe = frame[105:105 + 300, 104:104 + 512] cetergrayim = grayim[105:105 + 300, 104:104 + 512] filteredkps, surfrois = roiextract.surf_roi(cetergrayim, 512, 300) kpimg = cv2.drawKeypoints(ceterframe, filteredkps, None, (255, 0, 0), 4) personroi = [] filteredrois = roifilter.getFilteredROI(surfrois) for roi in filteredrois: if hogsvm.svmPredict(cetergrayim, roi) == 1: personroi.append(roi) print('person') cv2.imshow('surf keypoint', kpimg) cv2.waitKey(10) Visual.showResult(cetergrayim, personroi, winname='person roi', color=200) #color值越大越线条越偏白 if cv2.waitKey(1) == 32: print('space') while True: if (cv2.waitKey(1) == 32): break if outPath != None: #将结果写出到视频 videoWriter.write(kpimg) cv2.destroyAllWindows()