codeproject / CodeProject.AI-Server

CodeProject.AI Server is a self contained service that software developers can include in, and distribute with, their applications in order to augment their apps with the power of AI.
https://codeproject.github.io/codeproject.ai
Other
730 stars 159 forks source link

Allow loading of images via OpenCV #110

Closed seth-planet closed 6 months ago

seth-planet commented 7 months ago

Image resizing is so much faster with OpenCV due to threading and vector optimizations. In theory it should be as fast as 'pillow-simd', but in practice seems to be even 4x faster than 'pillow-simd'. On my Mac, OpenCV resizes 10x faster than default pillow (non-SIMD). Unfortunately, the OpenCV package is also 10x the size of pillow, too.

Note: PR currently proposed and untested.

For performance testing, see my post here: https://ipcamtalk.com/threads/codeproject-ai-version-2-5.74304/page-21#post-846822

seth-planet commented 7 months ago

Good to hear you’re on board with it; should be fixed now! ~Sethvia iPhoneOn Apr 26, 2024, at 5:57 AM, ChrisMaunder @.***> wrote: @ChrisMaunder requested changes on this pull request.

I love this idea: Just a couple of reviews though. The code doesn't seem to work as-is.

In src/SDK/Python/request_data.py:

             return None

img_stream hasn't yet been declared or assigned.

In src/SDK/Python/request_data.py:

@@ -135,11 +143,12 @@ def add_file(self, file_name: str) -> None: return self.payload["files"].append({ "data": RequestData.encode_file_contents(file_name) })

I would add -> Union[Image, numpy.ndarray]: as a return type hint

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

ChrisMaunder commented 7 months ago

Just merging this and will try and test tonight. Too much on my plate today. Getting worried beer o’clock could be compromised today.

cheers Chris

On Apr 26, 2024, at 11:30 AM, Seth Price @.***> wrote:

Good to hear you’re on board with it; should be fixed now! ~Sethvia iPhoneOn Apr 26, 2024, at 5:57 AM, ChrisMaunder @.***> wrote: @ChrisMaunder requested changes on this pull request.

I love this idea: Just a couple of reviews though. The code doesn't seem to work as-is.

In src/SDK/Python/request_data.py:

return None

  • img_file = self.files[index]
  • img_dataB64 = img_file["data"]
  • img_bytes = base64.b64decode(img_dataB64)
  • with io.BytesIO(img_bytes) as img_stream:
  • img = Image.open(img_stream).convert("RGB")
  • return img
  • if module == 'opencv':
  • assert 'cv' in sys.modules and 'np' in sys.modules
  • return cv.imdecode(np.frombuffer(img_stream, dtype=np.uint8), cv.IMREAD_COLOR)

img_stream hasn't yet been declared or assigned.

In src/SDK/Python/request_data.py:

@@ -135,11 +143,12 @@ def add_file(self, file_name: str) -> None: return self.payload["files"].append({ "data": RequestData.encode_file_contents(file_name) })

  • def get_image(self, index : int) -> Image:
  • def get_image(self, index : int, module: str = 'pil'):

I would add -> Union[Image, numpy.ndarray]: as a return type hint

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***> — Reply to this email directly, view it on GitHub https://github.com/codeproject/CodeProject.AI-Server/pull/110#issuecomment-2079620991, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDWW2MJ3LAKKS7PIUR2S4DY7JXLHAVCNFSM6AAAAABGRSE7FCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZZGYZDAOJZGE. You are receiving this because you were mentioned.

seth-planet commented 6 months ago

We should schedule a zoom hangout around beer o'clock sometime!

MikeLud commented 6 months ago

We should schedule a zoom hangout around beer o'clock sometime!

Count me in.

ChrisMaunder commented 6 months ago

I've merged the changes outside this pull request due to the faffing around we were doing with splitting out the repos. Will organise zoom call for this coming week