def test_create_rgba_image_from_array(self) -> None: image_1d_16 = numpy.zeros((16, ), dtype=numpy.double) image_1d_16x1 = numpy.zeros((16, 1), dtype=numpy.double) self.assertIsNotNone(Image.create_rgba_image_from_array(image_1d_16)) self.assertIsNotNone(Image.create_rgba_image_from_array(image_1d_16x1)) image_1d_rgb = numpy.zeros((16, 3), dtype=numpy.uint8) self.assertIsNotNone(Image.create_rgba_image_from_array(image_1d_rgb))
def test_rgba_can_be_created_from_h5py_array(self) -> None: current_working_directory = os.getcwd() workspace_dir = os.path.join(current_working_directory, "__Test") if os.path.exists(workspace_dir): shutil.rmtree(workspace_dir) os.makedirs(workspace_dir) try: with h5py.File(os.path.join(workspace_dir, "file.h5"), "w") as f: dataset = f.create_dataset("data", data=numpy.ones((4, 4, 4), dtype=numpy.uint8)) Image.create_rgba_image_from_array(dataset) finally: # print(f"rmtree {workspace_dir}") shutil.rmtree(workspace_dir)
def get_processed_data(self, data_sources, values): data = data_sources[0].data if data is None: return None img = Image.create_rgba_image_from_array(data) # inefficient since we're just converting back to gray if id(img) == id(data): img = img.copy() if id(img.base) == id(data): img = img.copy() img = img.view(numpy.uint8).reshape(img.shape + (4,)) # expand the color into uint8s img_gray = cv2.cvtColor(img, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) rects = detect(img_gray, relative_file(__file__, "haarcascade_frontalface_alt.xml")) draw_rects(img, rects, (0, 255, 0)) return img
def get_processed_data(self, data_sources, values): data = data_sources[0].data if data is None: return None img = Image.create_rgba_image_from_array( data) # inefficient since we're just converting back to gray if id(img) == id(data): img = img.copy() if id(img.base) == id(data): img = img.copy() img = img.view(numpy.uint8).reshape( img.shape + (4, )) # expand the color into uint8s img_gray = cv2.cvtColor(img, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) rects = detect( img_gray, relative_file(__file__, "haarcascade_frontalface_alt.xml")) draw_rects(img, rects, (0, 255, 0)) return img