diff --git a/.gitignore b/.gitignore index f1d9cb4f152103523a763b0ee6d6d67515a8239c..f03013e4f5e1219e996f316519fce459d0acbb8c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ etc/ +build-*/ build_*/ dataset_*/ binaries*/ diff --git a/Demo.py b/Demo.py index efa64cc1a60de50e2b34a91dc879d5e5265446d0..de7142f5dcffff938b6971d2d3e95b49900e0133 100644 --- a/Demo.py +++ b/Demo.py @@ -51,43 +51,43 @@ video_file = "dataset/video.avi" capture = cv2.VideoCapture(video_file) while not capture.isOpened(): - capture = cv2.VideoCapture(video_file) - cv2.waitKey(1000) - print("Wait for the header") + capture = cv2.VideoCapture(video_file) + cv2.waitKey(1000) + print("Wait for the header") #pos_frame = capture.get(cv2.cv.CV_CAP_PROP_POS_FRAMES) #pos_frame = capture.get(cv2.CV_CAP_PROP_POS_FRAMES) pos_frame = capture.get(1) while True: - flag, frame = capture.read() - - if flag: - cv2.imshow('video', frame) - #pos_frame = capture.get(cv2.cv.CV_CAP_PROP_POS_FRAMES) - #pos_frame = capture.get(cv2.CV_CAP_PROP_POS_FRAMES) - pos_frame = capture.get(1) - #print str(pos_frame)+" frames" - - img_output = bgs.apply(frame) - img_bgmodel = bgs.getBackgroundModel(); - - cv2.imshow('img_output', img_output) - cv2.imshow('img_bgmodel', img_bgmodel) + flag, frame = capture.read() + + if flag: + cv2.imshow('video', frame) + #pos_frame = capture.get(cv2.cv.CV_CAP_PROP_POS_FRAMES) + #pos_frame = capture.get(cv2.CV_CAP_PROP_POS_FRAMES) + pos_frame = capture.get(1) + #print str(pos_frame)+" frames" + + img_output = bgs.apply(frame) + img_bgmodel = bgs.getBackgroundModel(); + + cv2.imshow('img_output', img_output) + cv2.imshow('img_bgmodel', img_bgmodel) - else: - #capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, pos_frame-1) - #capture.set(cv2.CV_CAP_PROP_POS_FRAMES, pos_frame-1) - #capture.set(1, pos_frame-1) - #print "Frame is not ready" - cv2.waitKey(1000) - break - - if 0xFF & cv2.waitKey(10) == 27: - break - - #if capture.get(cv2.cv.CV_CAP_PROP_POS_FRAMES) == capture.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT): - #if capture.get(cv2.CV_CAP_PROP_POS_FRAMES) == capture.get(cv2.CV_CAP_PROP_FRAME_COUNT): - #if capture.get(1) == capture.get(cv2.CV_CAP_PROP_FRAME_COUNT): - #break + else: + #capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, pos_frame-1) + #capture.set(cv2.CV_CAP_PROP_POS_FRAMES, pos_frame-1) + #capture.set(1, pos_frame-1) + #print "Frame is not ready" + cv2.waitKey(1000) + break + + if 0xFF & cv2.waitKey(10) == 27: + break + + #if capture.get(cv2.cv.CV_CAP_PROP_POS_FRAMES) == capture.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT): + #if capture.get(cv2.CV_CAP_PROP_POS_FRAMES) == capture.get(cv2.CV_CAP_PROP_FRAME_COUNT): + #if capture.get(1) == capture.get(cv2.CV_CAP_PROP_FRAME_COUNT): + #break cv2.destroyAllWindows() diff --git a/fet/fet.py b/fet/fet.py index eeccc86762562f3c127cdcbe74773d30c8969b05..1f5602570f7b374f30141923c66d56349cec4f3c 100644 --- a/fet/fet.py +++ b/fet/fet.py @@ -11,6 +11,10 @@ import os from os import listdir from os.path import isfile, join +import sys +if sys.version_info >= (3, 0): + from six.moves import xrange + path_gt = 'GT/' path_fg = 'FG/' path_sc = 'SC/' @@ -40,54 +44,54 @@ red = [0,0,255] # for FP white = [255,255,255] # for TP black = [0,0,0] # for TN -print 'Processing' +print('Processing') k = 1 for file_gt, file_fg in zip(files_gt, files_fg): - print(k, file_gt, file_fg) - img_gt = cv2.imread(path_gt + file_gt,cv2.IMREAD_GRAYSCALE) - img_fg = cv2.imread(path_fg + file_fg,cv2.IMREAD_GRAYSCALE) - # img_gt = cv2.resize(img_gt, (0,0), fx=0.5, fy=0.5) - # print(img_gt.shape,img_fg.shape) - rows,cols = img_gt.shape - img_fg = cv2.resize(img_fg,(cols,rows)) - img_res = np.zeros((rows,cols,3),np.uint8) - for i in xrange(rows): - for j in xrange(cols): - pixel_gt = img_gt[i,j] - pixel_fg = img_fg[i,j] - if(pixel_gt == 255 and pixel_fg == 255): - TP = TP + 1 - img_res[i,j] = white - if(pixel_gt == 0 and pixel_fg == 255): - FP = FP + 1 - img_res[i,j] = red - if(pixel_gt == 0 and pixel_fg == 0): - TN = TN + 1 - img_res[i,j] = black - if(pixel_gt == 255 and pixel_fg == 0): - FN = FN + 1 - img_res[i,j] = green - cv2.imshow('GT',img_gt) - cv2.imshow('FG',img_fg) - cv2.imshow('SC',img_res) - cv2.imwrite(path_sc + file_gt, img_res) - cv2.waitKey(1) # 33 - k = k + 1 - #break + print(k, file_gt, file_fg) + img_gt = cv2.imread(path_gt + file_gt,cv2.IMREAD_GRAYSCALE) + img_fg = cv2.imread(path_fg + file_fg,cv2.IMREAD_GRAYSCALE) + # img_gt = cv2.resize(img_gt, (0,0), fx=0.5, fy=0.5) + # print(img_gt.shape,img_fg.shape) + rows,cols = img_gt.shape + img_fg = cv2.resize(img_fg,(cols,rows)) + img_res = np.zeros((rows,cols,3),np.uint8) + for i in xrange(rows): + for j in xrange(cols): + pixel_gt = img_gt[i,j] + pixel_fg = img_fg[i,j] + if(pixel_gt == 255 and pixel_fg == 255): + TP = TP + 1 + img_res[i,j] = white + if(pixel_gt == 0 and pixel_fg == 255): + FP = FP + 1 + img_res[i,j] = red + if(pixel_gt == 0 and pixel_fg == 0): + TN = TN + 1 + img_res[i,j] = black + if(pixel_gt == 255 and pixel_fg == 0): + FN = FN + 1 + img_res[i,j] = green + cv2.imshow('GT',img_gt) + cv2.imshow('FG',img_fg) + cv2.imshow('SC',img_res) + cv2.imwrite(path_sc + file_gt, img_res) + cv2.waitKey(1) # 33 + k = k + 1 + #break cv2.destroyAllWindows() Recall = TP / (TP + FN) Precision = TP / (TP + FP) Fscore = 2*Precision*Recall/(Precision+Recall) -print 'Score:' -print 'TP: ', TP -print 'FP: ', FP -print 'TN: ', TN -print 'FN: ', FN -print 'Recall: ', Recall -print 'Precision: ', Precision -print 'Fscore: ', Fscore -print '' +print('Score:') +print('TP: ', TP) +print('FP: ', FP) +print('TN: ', TN) +print('FN: ', FN) +print('Recall: ', Recall) +print('Precision: ', Precision) +print('Fscore: ', Fscore) +print('') ##################################################################### diff --git a/gui_qt/.gitignore b/gui_qt/.gitignore index 9c28032b4c6631a5f27072a12901a0fecd324309..e3317f8f13699242452b3916cc1a2bacff78a91c 100644 --- a/gui_qt/.gitignore +++ b/gui_qt/.gitignore @@ -7,3 +7,4 @@ binaries*/ Makefile* *.exe *.dll +*.pro.user diff --git a/gui_qt/CMakeLists.txt b/gui_qt/CMakeLists.txt index 191207255d2cc1823342e0c0370924a1bdbd49ae..effd47fa526022be94ff701e113ca064a99f25fc 100644 --- a/gui_qt/CMakeLists.txt +++ b/gui_qt/CMakeLists.txt @@ -27,6 +27,8 @@ set(CMAKE_AUTOUIC ON) # Find the Qt5Widgets library find_package(Qt5Widgets) +# To fix the issue: https://stackoverflow.com/questions/38557755/cmake-cant-seem-to-find-needed-qt-cmake-files-even-though-ive-set-cmake-prefix +#find_package(Qt5Widgets CONFIG PATHS C:/Qt/5.11.1/msvc2017_64/lib/cmake NO_DEFAULT_PATH) if(Qt5Widgets_FOUND) message(STATUS "Qt5Widgets status:") message(STATUS " version: ${Qt5Widgets_VERSION}") diff --git a/gui_qt/bgslibrary_gui.pro b/gui_qt/bgslibrary_gui.pro index feedbf6a8601455aaad465d68842e76928c92a3a..9486d316741421400361584565352f207b91d595 100644 --- a/gui_qt/bgslibrary_gui.pro +++ b/gui_qt/bgslibrary_gui.pro @@ -16,8 +16,13 @@ TEMPLATE = app #LIBS += -LC:/OpenCV3.1.0/build/x64/vc14/lib -lopencv_world310 # For Windows x64 + Visual Studio 2015 + OpenCV 3.2.0 -INCLUDEPATH += C:/OpenCV3.2.0/build/include -LIBS += -LC:/OpenCV3.2.0/build/x64/vc14/lib -lopencv_world320 +#INCLUDEPATH += C:/OpenCV3.2.0/build/include +#LIBS += -LC:/OpenCV3.2.0/build/x64/vc14/lib -lopencv_world320 + +# For Windows x64 + Visual Studio 2017 + OpenCV 3.4.2 +INCLUDEPATH += E:/OpenCV3.4.2/build/include +INCLUDEPATH += E:/OpenCV3.4.2/build/include/opencv +LIBS += -LE:/OpenCV3.4.2/build/x64/vc15/lib -lopencv_world342 # For Linux # INCLUDEPATH += /usr/local/include/opencv @@ -124,7 +129,8 @@ SOURCES += bgslibrary_gui.cpp\ ../package_bgs/VuMeter.cpp \ ../package_bgs/WeightedMovingMean.cpp \ ../package_bgs/WeightedMovingVariance.cpp \ - ../package_bgs/_template_/amber/amber.c + ../package_bgs/_template_/amber/amber.c \ + ../package_bgs/CodeBook.cpp HEADERS += mainwindow.h \ qt_utils.h \ @@ -236,7 +242,8 @@ HEADERS += mainwindow.h \ ../package_bgs/ViBe.h \ ../package_bgs/VuMeter.h \ ../package_bgs/WeightedMovingMean.h \ - ../package_bgs/WeightedMovingVariance.h + ../package_bgs/WeightedMovingVariance.h \ + ../package_bgs/CodeBook.h FORMS += mainwindow.ui