2

I currently have a python socket server that captures from a webcam using opencv. I have converted the captured image using image.tostring();

I am trying to send this image to an android application and have it open in a web view. I can get the text string to open, but cannot make it back into an image.

This is the only way that I can get anything to display in the web view :

webv.loadData(html, "text/html", "utf-8");

The data is transferring to the android device, so I know that the socket is working fine, I just cannot figure out the translation.

Any suggestions?

EDIT based on comments below:

Ok. So I now converted the string to base64 in python, before sending it.

I tried using bitmapfactory to add the image to an ImageView using:

byte[] decodedString = Base64.decode(result, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

but I get the error SkImageDecoder:: Factory returned null

I also tried a webview with the following, which gives me a broken image icon

String html = "<img src=\"data:image/jpeg;base64,"+result+"\" />";
webv.loadData(html, "text/html", "utf-8");

These give me a blank webview

String html = "<img src=\"data:image/jpeg;base64,"+result+"\" />";
webv.loadData(html, "iamge/jpeg", "base64");

String html = "<img src=\"data:image/jpeg;base64,"+result+"\" />";
webv.loadData(html, "text/html", "base64");

webv.loadData(result, "image/jpeg","base64");

It seems that the problem is in my python code, as the base64 string exported to a text file cannot be reformed into an image, it "contains errors" applicable code fragments:

img = cv.QueryFrame(cam)
imgstr = base64.b64encode(img.tostring())

conn = s.accept()
conn.send(imgstr)
saniel
  • 23
  • 5
  • Two things to try: Save your payload to your device then inspect it with gdb. I suspect the file will be corrupted. If so, base64 encode the string and then send it to the device ( http://developer.android.com/reference/android/util/Base64.html ) – David May 03 '13 at 15:40
  • Thanks! made some edits to the original question I haven't used gdb before. I am trying to wrap my head around it. @David – saniel May 03 '13 at 16:18
  • Just thought of this, are you going straight from cv.Image().toString() or are you transforming that into a jpeg before sending it? It's been a while but I am pretty sure that cv.Image().toString() format is in a BMP format. – David May 03 '13 at 17:00
  • Also, I missed type - I meant ADB not GDB. The android debug bridge also has a utility to pull files from a device and make them local, which can make debugging a lot easier. – David May 03 '13 at 17:11
  • Ok. I will try ADB. I am trying to figure out how to convert the cv image to a jpeg, because I think that you are right about that. – saniel May 03 '13 at 18:10
  • Converting from raw/bmp to jpg should be trivial if you have PIL or similar available – David May 03 '13 at 18:43
  • I am having trouble finding a way to do it without saving the file to the local disk. – saniel May 03 '13 at 19:04
  • http://stackoverflow.com/questions/646286/python-pil-how-to-write-png-image-to-string – David May 03 '13 at 19:06
  • Thanks! got that, but it is still not displaying the image. – saniel May 03 '13 at 22:00
  • Last idea from me, save the jpg locally before you send it. Verify its correct. Then save the jpg on the android and pull it off with adb and reverify you got the correct payload. – David May 03 '13 at 22:15

0 Answers0