Skip to content

Commit

Permalink
coreml: dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Apr 13, 2024
1 parent 35de80e commit 250b255
Showing 1 changed file with 51 additions and 53 deletions.
104 changes: 51 additions & 53 deletions plugins/coreml/src/coreml/recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# import Quartz
import scrypted_sdk
# from Foundation import NSData, NSMakeSize
from PIL import Image, ImageOps
from PIL import Image
from scrypted_sdk import (
Setting,
SettingValue,
Expand All @@ -23,9 +23,8 @@
import traceback

# import Vision
from predict import Prediction, PredictPlugin, from_bounding_box
from predict import PredictPlugin
from common import yolo
from common.softmax import softmax
from common.text import prepare_text_result, process_text_result

def euclidean_distance(arr1, arr2):
Expand All @@ -42,7 +41,6 @@ def cosine_similarity(vector_a, vector_b):

predictExecutor = concurrent.futures.ThreadPoolExecutor(8, "Vision-Predict")


class CoreMLRecognition(PredictPlugin):
def __init__(self, nativeId: str | None = None):
super().__init__(nativeId=nativeId)
Expand Down Expand Up @@ -104,58 +102,58 @@ def get_input_size(self) -> Tuple[float, float]:
def get_input_format(self) -> str:
return "rgb"

def predictVision(self, input: Image.Image) -> asyncio.Future[list[Prediction]]:
buffer = input.tobytes()
myData = NSData.alloc().initWithBytes_length_(buffer, len(buffer))

input_image = (
Quartz.CIImage.imageWithBitmapData_bytesPerRow_size_format_options_(
myData,
4 * input.width,
NSMakeSize(input.width, input.height),
Quartz.kCIFormatRGBA8,
None,
)
)
# def predictVision(self, input: Image.Image) -> asyncio.Future[list[Prediction]]:
# buffer = input.tobytes()
# myData = NSData.alloc().initWithBytes_length_(buffer, len(buffer))

# input_image = (
# Quartz.CIImage.imageWithBitmapData_bytesPerRow_size_format_options_(
# myData,
# 4 * input.width,
# NSMakeSize(input.width, input.height),
# Quartz.kCIFormatRGBA8,
# None,
# )
# )

request_handler = Vision.VNImageRequestHandler.alloc().initWithCIImage_options_(
input_image, None
)
# request_handler = Vision.VNImageRequestHandler.alloc().initWithCIImage_options_(
# input_image, None
# )

loop = self.loop
future = loop.create_future()

def detect_face_handler(request, error):
observations = request.results()
if error:
loop.call_soon_threadsafe(future.set_exception, Exception())
else:
objs = []
for o in observations:
confidence = o.confidence()
bb = o.boundingBox()
origin = bb.origin
size = bb.size

l = origin.x * input.width
t = (1 - origin.y - size.height) * input.height
w = size.width * input.width
h = size.height * input.height
prediction = Prediction(
0, confidence, from_bounding_box((l, t, w, h))
)
objs.append(prediction)

loop.call_soon_threadsafe(future.set_result, objs)

request = (
Vision.VNDetectFaceRectanglesRequest.alloc().initWithCompletionHandler_(
detect_face_handler
)
)
# loop = self.loop
# future = loop.create_future()

# def detect_face_handler(request, error):
# observations = request.results()
# if error:
# loop.call_soon_threadsafe(future.set_exception, Exception())
# else:
# objs = []
# for o in observations:
# confidence = o.confidence()
# bb = o.boundingBox()
# origin = bb.origin
# size = bb.size

# l = origin.x * input.width
# t = (1 - origin.y - size.height) * input.height
# w = size.width * input.width
# h = size.height * input.height
# prediction = Prediction(
# 0, confidence, from_bounding_box((l, t, w, h))
# )
# objs.append(prediction)

# loop.call_soon_threadsafe(future.set_result, objs)

# request = (
# Vision.VNDetectFaceRectanglesRequest.alloc().initWithCompletionHandler_(
# detect_face_handler
# )
# )

error = request_handler.performRequests_error_([request], None)
return future
# error = request_handler.performRequests_error_([request], None)
# return future

# async def detect_once(self, input: Image.Image, settings: Any, src_size, cvss):
# future = await asyncio.get_event_loop().run_in_executor(
Expand Down

0 comments on commit 250b255

Please sign in to comment.