0

I'm making a face recognition app that uses local camera to capture the face and encodes it into a 128-d numpy array via chaquopy. What I want to make is to send that numpy array over network to a server. The problem is I dont know how to send a numpy array via network or a chaquopy-PyObject efficiently. Please give me advices

I can convert the numpy array into a json file or a string but this time it'll take really long time to execute. Speed is really important so the solution should be the closest to the most efficient way.

1 Answers1

0

You could convert the array directly to bytes using tobytes, or at a slightly higher level using save. See this question for further discussion.

mhsmith
  • 6,675
  • 3
  • 41
  • 58
  • For example, if I were to return that numpy array from python would I still be able to send it over network from java as pyobject? Speed is really important so least amount of conversion would suit me more – Taner Caslaman Nov 14 '22 at 10:05
  • If you want to handle the network connection on the Java side, then the most efficient solution would be to convert the numpy array to bytes in Python, return the `bytes` object to Java, and convert it using [`toJava(byte[].class)`](https://chaquo.com/chaquopy/doc/current/java/com/chaquo/python/PyObject.html#toJava(java.lang.Class)). – mhsmith Nov 14 '22 at 14:16
  • Do you think creating TCP conncetion in java and passing ip adress and port to the python and sending data from there would be more efficient ? – Taner Caslaman Nov 17 '22 at 23:42
  • It probably wouldn't make any difference: passing byte arrays between Python and Java is very efficient. So I recommend you first implement your app in the simplest possible way, and then if it's too slow, do some timing tests to work out exactly where the problem is. – mhsmith Nov 18 '22 at 15:06
  • Thanks, I'll definitely try that – Taner Caslaman Nov 18 '22 at 17:32