зеркало из
				https://github.com/ssciwr/AMMICO.git
				synced 2025-10-30 13:36:04 +02:00 
			
		
		
		
	 fdcb228294
			
		
	
	
		fdcb228294
		
			
		
	
	
	
	
		
			
			* colors expression by KMean algorithm * object detection by imageai * object detection by cvlib * add encapsulation of object detection * remove encapsulation of objdetect v0 * objects expression to dict * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * added imageai to requirements * add objects to dictionary * update for AnalysisMethod baseline * add objects dection support explore_analysis display * extend python version of misinf to allow imageai * account for older python * use global functionality for dict to csv convert * update for docker build * docker will build now but ipywidgets still not working * test code * include test data folder in repo * add some sample images * load cvs labels to dict * add test data * retrigger checks * add map to human coding * get orders from dict, missing dep * add module to test accuracy * retrigger checks * retrigger checks * now removing imageai * removed imageai * move labelmanager to analyse * multiple faces in mydict * fix pre-commit issues * map mydict * hide imageai * objects default using cvlib, isolate and disable imageai * correct python version * refactor faces tests * refactor objects tests * sonarcloud issues * refactor utils tests * address code smells * update readme * update notebook without imageai Co-authored-by: Ma Xianghe <825074348@qq.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: iulusoy <inga.ulusoy@uni-heidelberg.de>
		
			
				
	
	
		
			78 строки
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			78 строки
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import cv2
 | |
| import cvlib as cv
 | |
| 
 | |
| 
 | |
| def objects_from_cvlib(objects_list: list) -> dict:
 | |
|     objects = init_default_objects()
 | |
|     for key in objects:
 | |
|         if key in objects_list:
 | |
|             objects[key] = "yes"
 | |
|     return objects
 | |
| 
 | |
| 
 | |
| def init_default_objects():
 | |
|     objects = {
 | |
|         "person": "no",
 | |
|         "bicycle": "no",
 | |
|         "car": "no",
 | |
|         "motorcycle": "no",
 | |
|         "airplane": "no",
 | |
|         "bus": "no",
 | |
|         "train": "no",
 | |
|         "truck": "no",
 | |
|         "boat": "no",
 | |
|         "traffic light": "no",
 | |
|         "cell phone": "no",
 | |
|     }
 | |
|     return objects
 | |
| 
 | |
| 
 | |
| class ObjectsMethod:
 | |
|     """Base class to be inherited by all objects methods."""
 | |
| 
 | |
|     def __init__(self):
 | |
|         # initialize in child class
 | |
|         pass
 | |
| 
 | |
|     def analyse_image(self, subdict):
 | |
|         raise NotImplementedError()
 | |
| 
 | |
| 
 | |
| class ObjectCVLib(ObjectsMethod):
 | |
|     def __init__(self, client_type=1):
 | |
|         # as long as imageai is not activated this remains empty
 | |
|         pass
 | |
| 
 | |
|     def detect_objects_cvlib(self, image_path):
 | |
|         """Localize objects in the local image.
 | |
| 
 | |
|         Args:
 | |
|         image_path: The path to the local file.
 | |
|         """
 | |
|         img = cv2.imread(image_path)
 | |
|         bbox, label, conf = cv.detect_common_objects(img)
 | |
|         # output_image = draw_bbox(im, bbox, label, conf)
 | |
|         objects = objects_from_cvlib(label)
 | |
|         return objects
 | |
| 
 | |
|     def analyse_image_from_file(self, image_path):
 | |
|         """Localize objects in the local image.
 | |
| 
 | |
|         Args:
 | |
|         image_path: The path to the local file.
 | |
|         """
 | |
|         objects = self.detect_objects_cvlib(image_path)
 | |
|         return objects
 | |
| 
 | |
|     def analyse_image(self, subdict):
 | |
|         """Localize objects in the local image.
 | |
| 
 | |
|         Args:
 | |
|         subdict: The dictionary for an image expression instance.
 | |
|         """
 | |
|         objects = self.analyse_image_from_file(subdict["filename"])
 | |
|         for key in objects:
 | |
|             subdict[key] = objects[key]
 | |
| 
 | |
|         return subdict
 |