| 646 | |
| 647 | |
| 648 | class Image2Depth: |
| 649 | def __init__(self, device): |
| 650 | print("Initializing Image2Depth") |
| 651 | self.depth_estimator = pipeline('depth-estimation') |
| 652 | |
| 653 | @prompts(name="Predict Depth On Image", |
| 654 | description="useful when you want to detect depth of the image. like: generate the depth from this image, " |
| 655 | "or detect the depth map on this image, or predict the depth for this image. " |
| 656 | "The input to this tool should be a string, representing the image_path") |
| 657 | def inference(self, inputs): |
| 658 | image = Image.open(inputs) |
| 659 | depth = self.depth_estimator(image)['depth'] |
| 660 | depth = np.array(depth) |
| 661 | depth = depth[:, :, None] |
| 662 | depth = np.concatenate([depth, depth, depth], axis=2) |
| 663 | depth = Image.fromarray(depth) |
| 664 | updated_image_path = get_new_image_name(inputs, func_name="depth") |
| 665 | depth.save(updated_image_path) |
| 666 | print(f"\nProcessed Image2Depth, Input Image: {inputs}, Output Depth: {updated_image_path}") |
| 667 | return updated_image_path |
| 668 | |
| 669 | |
| 670 | class DepthText2Image: |
nothing calls this directly
no outgoing calls
no test coverage detected