예제 #1
0
 def __init__(self, fname_path):
     assert os.path.exists(fname_path), f'file {fname_path} does not exists'
     self.fname_path = fname_path
     self.datetime = self.extract_datetime(fname_path)
     self.fie = flir_image_extractor.FlirImageExtractor(
         image_suffix="v.jpg", thermal_suffix="t.png")
     self.fie.process_image(fname_path)
     self.visual_np = self.fie.get_rgb_np()
     self.thermal_np = self.fie.get_thermal_np()
     self.marks_list = qr_read.QrMarkList(self.visual_np)
     # self.meters = [Meter(mark,self.thermal_np) for mark in self.marks_list.marks] # init meters:
     self.vis_therm_ratio = (self.visual_np.shape[0] /
                             self.thermal_np.shape[0],
                             self.visual_np.shape[1] /
                             self.thermal_np.shape[1])
예제 #2
0
    def getCsvData(self, jpgfile, csvfile, plot=False):

        start = time.time()

        fie = flir_image_extractor.FlirImageExtractor()
        fie.process_image(jpgfile)

        fie.export_thermal_to_csv(csvfile)

        end = time.time()

        print("Thermal data in picture " + jpgfile + " written to " + csvfile +
              " in " + str(end - start) + " s.")

        if (plot):
            fie.plot()
예제 #3
0
def main():

    fir = flir_image_extractor.FlirImageExtractor(image_suffix="v.jpg",
                                                  thermal_suffix="t.png")
    for dir in next(os.walk(input_folder))[1]:
        dir_start_time = time.perf_counter()
        dir_file_counter = 0
        dir_path = os.path.join(input_folder, dir)

        log = get_all_logs(dir_path)
        print(f"folder:{dir_path} len(log)={len(log)}")
        for jpg_file in glob.glob(dir_path + '/' + '*.jpg'):
            fname_timestamp = flirfname_2_dt(jpg_file)
            log_entry = get_log_entry(log, fname_timestamp)
            if log_entry is not None:
                new_fname = get_new_fname(log_entry, fname_timestamp)
                new_folder = get_new_folder(log_entry, result_folder)
                new_fname_path = os.path.join(new_folder, new_fname)
                shutil.copyfile(jpg_file, new_fname_path)
                print(f"{jpg_file} ---> {new_folder}/{new_fname})")
                if need_fir:
                    fir.process_image(new_fname_path)
                    fir.save_images()
            else:  # log entry isn't found
                folder = os.path.join(result_folder, not_logged_folder)
                os.makedirs(folder, exist_ok=True)
                os.rename(jpg_file,
                          os.path.join(folder, os.path.basename(jpg_file)))
                print(
                    f"{jpg_file} moved to {folder} since related log entry is not found"
                )
            dir_file_counter += 1

        copy_to_archive(dir_path)
        shutil.rmtree(dir_path, ignore_errors=True)
        os.rmdir(dir_path)
        dt = time.perf_counter() - dir_start_time
        print(
            f"{dir_path}: processed {dir_file_counter} files in {dt/60.:.0f} minutes",
            f" avg speed = {dt/dir_file_counter:.0f} sec/file")
예제 #4
0
    def __init__(self, fname_path, skip_thermal=False):
        assert os.path.exists(fname_path), f'file {fname_path} does not exists'
        self.fname_path = fname_path
        self.datetime = self.extract_datetime()
        self.fie = flir_image_extractor.FlirImageExtractor(
            image_suffix="v.jpg", thermal_suffix="t.png")
        cached_thermal = ImageFiles.get_cached_thermal(
            fname_path) if Cfg.cache_thermal_allowed else None
        self.fie.process_image(fname_path, cached_thermal, skip_thermal)
        self.flir_img = self.get_flir_image(fname_path)
        self.visual_img = self.fie.get_rgb_np()
        self.thermal_np = self.fie.get_thermal_np()
        thermal_normalized = (self.thermal_np - np.amin(self.thermal_np)) \
                             / (np.amax(self.thermal_np) - np.amin(self.thermal_np))
        self.thermal_img = np.array(
            np.uint8(cm.inferno(thermal_normalized) * 255))  # inferno,gray
        self.thermal_img = cv.cvtColor(self.thermal_img, cv.COLOR_RGBA2BGR)

        self.vis_therm_ratio = (self.visual_img.shape[0] /
                                self.thermal_np.shape[0],
                                self.visual_img.shape[1] /
                                self.thermal_np.shape[1])
        if self.flir_img.shape[0] > self.flir_img.shape[1]:  # vertical
            # transpose
            # self.flir_img = cv.transpose(self.flir_img)
            # self.visual_img = cv.transpose(self.visual_img)
            # self.thermal_np = cv.transpose(self.thermal_np)
            # self.thermal_img = cv.transpose(self.thermal_img)
            # rotate
            self.flir_img = np.rot90(self.flir_img)
            self.visual_img = np.rot90(self.visual_img)
            self.thermal_np = np.rot90(self.thermal_np)
            self.thermal_img = np.rot90(self.thermal_img)

        self.image_id = ImageFiles.save(self.datetime, self.flir_img,
                                        self.visual_img, self.thermal_np)
        self.skip_thermal = skip_thermal
# 구글 API 설정
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r'ServiceAccountToken.json'
client = vision.ImageAnnotatorClient()

facenet = cv2.dnn.readNet(
    '../training custom dataset/face_detector/deploy.prototxt',
    '../training custom dataset/face_detector/res10_300x300_ssd_iter_140000.caffemodel'
)
# FaceDetector 모델 > OpenCv의 DNN
model = load_model('../training custom dataset/mask_detector.model')
# MaskDetector 모델 > Keras 모델
# cv2.VideoWriter(outputFile, fourcc, frame, size) : fourcc는 코덱 정보, frame은 초당 저장될 프레임, size는 저장될 사이즈를 뜻합니다 cv2.VideoWriter_fourcc('D','I','V','X') 이런식으로 사용
# 현재 테스트 동영상의 프레임은 25

thermal_camera = Lepton()
fir = flir_image_extractor.FlirImageExtractor()

cap = cv2.VideoCapture(0)
# 동영상 로드
ret, img = cap.read()
# ret이 True이면 영상이 있다는 뜻
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
out = cv2.VideoWriter('output.mp4', fourcc, 1, (img.shape[1], img.shape[0]))
# cv2.VideoWriter(outputFile, fourcc, frame, size) : fourcc는 코덱 정보, frame은 초당 저장될 프레임, size는 저장될 사이즈를 뜻합니다 cv2.VideoWriter_fourcc('D','I','V','X') 이런식으로 사용
# 현재 테스트 동영상의 프레임은 25
number = 0  # 마스크 안 쓴 사람 사진 저장할 때 사용


def get_max_temperature(thermal_np, x1, y1, x2, y2):
    # 온도 데이터에서 얼굴 영역만 잘라서 검사함
    crop = thermal_np[y1:y2, x1:x2]