Skip to content

Commit

Permalink
Add Image size settings
Browse files Browse the repository at this point in the history
  • Loading branch information
karakurai committed Jan 30, 2024
1 parent 504324d commit 095f281
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
4 changes: 3 additions & 1 deletion conf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use_camera_1 = True
use_camera_2 = True
use_camera_3 = True
use_camera_4 = True
display_fps = 5
image_max_width = 800
image_max_height = 800
display_fps = 3
multi_frame_smoothing_flg = False
adfi_api_url = https://us.adfi.karakurai.com/API/ap/api/apidata/
dataset_dir = ./dataset
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def start_cs_screen(self, lang):
else:
self.sm.current = "camera_setting"

def resize_cv_image(self, cv_image, size_max=(900, 500)):
def resize_cv_image(self, cv_image, size_max=(650, 500)):
if cv_image is not None:
height = cv_image.shape[0]
width = cv_image.shape[1]
Expand Down
52 changes: 40 additions & 12 deletions main_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from concurrent.futures import ThreadPoolExecutor

import cv2
from adfi_api import AdfiApi
from image_processing import ImageProcessing
from kivy.clock import Clock
from kivy.graphics import Color, Line, Rectangle
from kivy.graphics.texture import Texture
Expand All @@ -20,6 +18,9 @@
from kivymd.uix.floatlayout import MDFloatLayout
from kivymd.uix.screen import MDScreen

from adfi_api import AdfiApi
from image_processing import ImageProcessing


class MainScreen(MDScreen):
def __init__(self, **kwargs):
Expand Down Expand Up @@ -131,7 +132,10 @@ def __init__(self, **kwargs):
self.image_processing = ImageProcessing()
self.screen = None
self.pos = (300, 270)
self.image_size = (500, 500)
self.image_size = (
int(self.app.confini["settings"]["image_max_width"]),
int(self.app.confini["settings"]["image_max_height"]),
)
self.full_frame = [None] * 5
self.frame = [None] * 5
self.frame_list = [None] * 5
Expand Down Expand Up @@ -170,7 +174,9 @@ def change_image(self):
]

def start_clock(self):
Clock.schedule_interval(self.clock_capture, 1.0 / float(self.app.confini["settings"]["display_fps"]))
Clock.schedule_interval(
self.clock_capture, 1.0 / float(self.app.confini["settings"]["display_fps"])
)

def stop_clock(self):
Clock.unschedule(self.clock_capture)
Expand Down Expand Up @@ -242,6 +248,7 @@ def clock_capture(self, dt):
}
)
if i == self.current_image_num:
tmp_frame = self.app.resize_cv_image(tmp_frame)
flip_frame = cv2.flip(tmp_frame, 0)
if flip_frame is not None:
buf = flip_frame.tobytes()
Expand Down Expand Up @@ -301,9 +308,7 @@ def clock_capture(self, dt):
)
img_count += 1
self.processing = 0
with ThreadPoolExecutor(
max_workers=img_count
) as executor:
with ThreadPoolExecutor(max_workers=img_count) as executor:
for j in range(len(settings_list)):
if save_image_path[j] != "":
self.screen.ids[
Expand Down Expand Up @@ -337,11 +342,25 @@ def do_inspection(
time.sleep(index * 0.1)
if not os.path.exists(self.app.confini["settings"]["result_csv_dir"]):
os.makedirs(self.app.confini["settings"]["result_csv_dir"])
result_csv_path = self.app.confini["settings"]["result_csv_dir"] + "/" + datetime.datetime.now().strftime("%Y%m") + "_result.csv"
result_csv_path = (
self.app.confini["settings"]["result_csv_dir"]
+ "/"
+ datetime.datetime.now().strftime("%Y%m")
+ "_result.csv"
)
if not os.path.exists(result_csv_path):
with open(result_csv_path, "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["image_name", "result", "time", "anomaly_score", "main_prediction_result", "sub_prediction_result"])
writer.writerow(
[
"image_name",
"result",
"time",
"anomaly_score",
"main_prediction_result",
"sub_prediction_result",
]
)

self.processing += 1
cv2.imwrite(
Expand Down Expand Up @@ -385,18 +404,27 @@ def do_inspection(
if result_json is not None:
with open(result_csv_path, "a", newline="") as f:
writer = csv.writer(f)
writer.writerow([result_json["image_name"], result_json["result"], result_json["time"], result_json["anomaly_score"], result_json["main_prediction_result"], result_json["sub_prediction_result"]])
writer.writerow(
[
result_json["image_name"],
result_json["result"],
result_json["time"],
result_json["anomaly_score"],
result_json["main_prediction_result"],
result_json["sub_prediction_result"],
]
)
self.result_image_path_list[int(index)] = result_image_save_path
self.processing -= 1

def show_image(self, result_num):
inspection_img_path = self.inspection_image_path_list[int(result_num)]
if inspection_img_path is not None and os.path.exists(inspection_img_path):
img = cv2.imread(inspection_img_path)
cv2.imshow('Inspection Image ' + str(result_num), img)
cv2.imshow("Inspection Image " + str(result_num), img)
cv2.waitKey(1)
result_img_path = self.result_image_path_list[int(result_num)]
if result_img_path is not None and os.path.exists(result_img_path):
img = cv2.imread(result_img_path)
cv2.imshow('Result Image ' + str(result_num), img)
cv2.imshow("Result Image " + str(result_num), img)
cv2.waitKey(1)
13 changes: 10 additions & 3 deletions making_dataset_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import webbrowser

import cv2
from image_processing import ImageProcessing
from kivy.clock import Clock
from kivy.graphics import Color, Line, Rectangle
from kivy.graphics.texture import Texture
Expand All @@ -16,6 +15,8 @@
from kivymd.uix.floatlayout import MDFloatLayout
from kivymd.uix.screen import MDScreen

from image_processing import ImageProcessing


class MakingDatasetScreen(MDScreen):
def __init__(self, **kwargs):
Expand Down Expand Up @@ -79,7 +80,10 @@ def __init__(self, **kwargs):
self.image_processing = ImageProcessing()
self.screen = None
self.pos = (200, 200)
self.image_size = (500, 500)
self.image_size = (
int(self.app.confini["settings"]["image_max_width"]),
int(self.app.confini["settings"]["image_max_height"]),
)
self.full_frame = [None] * 5
self.frame = [None] * 5
self.frame_list = [None] * 5
Expand Down Expand Up @@ -112,7 +116,9 @@ def change_image(self):
][self.current_image_num]["NAME"]

def start_clock(self):
Clock.schedule_interval(self.clock_capture, 1.0 / float(self.app.confini["settings"]["display_fps"]))
Clock.schedule_interval(
self.clock_capture, 1.0 / float(self.app.confini["settings"]["display_fps"])
)

def stop_clock(self):
Clock.unschedule(self.clock_capture)
Expand Down Expand Up @@ -181,6 +187,7 @@ def clock_capture(self, dt):
}
)
if count == self.current_image_num:
tmp_frame = self.app.resize_cv_image(tmp_frame)
flip_frame = cv2.flip(tmp_frame, 0)
if flip_frame is not None:
buf = flip_frame.tobytes()
Expand Down

0 comments on commit 095f281

Please sign in to comment.