In [219]:
from subprocess import call
data=open("puzzle.jpg").read()
In [220]:
# ./jpegdump puzzle.jpg |grep SOI|cut -d ' ' -f 6|cut -f 1 > jpeg_pos
lines = open("jpeg_pos").read().splitlines()
pos = map(int, lines)
print pos
for i in range(len(pos)-1):    
    with open("tt/u%03d.jpg"%i, "w") as f:
        f.write(data[pos[i]:pos[i+1]])
    # http://svn.emphy.de/nanojpeg/trunk/nanojpeg/nanojpeg.c
    call(["./jpg", "tt/u%03d.jpg"%i, "xx/u%03d.ppm"%i])
num_imgs = i+1
print num_imgs
[0, 30, 5427, 10876, 16126, 20918, 22965, 28794, 33761, 35746, 37488, 43488, 45338, 49819, 53875, 59647, 61325, 62921, 67075, 72203, 74364, 81068, 83079, 87531, 93891, 98070, 99962, 101921, 104393, 109045, 111512, 113831, 118996, 123023, 128741, 133694, 138617, 140405, 146022, 149088, 154420, 160799, 165707, 171362, 177181, 179046, 183680, 185555, 187223, 193070, 195464, 198443, 203996, 206003, 208130, 214139, 219540, 225816, 227781, 232178, 233903, 238980, 240890, 243279, 245210, 246970, 252150, 253893, 255714, 257378, 262413, 264153, 266200, 268254, 270340, 272290, 274169, 276138, 281297, 286099, 291862, 293885, 299377, 301561, 303325, 305320, 306982, 309132, 313884, 319747, 325721, 330189, 335313, 337060, 341149, 346404, 350697, 356848, 359221, 365025, 367090, 371257]
101
In [221]:
%matplotlib inline
import numpy as np
import cv2
import matplotlib.pyplot as plt
import os
import cv
import sys
from IPython.html.widgets import interact, interactive, fixed
from IPython.display import clear_output, display, HTML
from IPython.html import widgets
In [222]:
imgs = [cv2.imread("xx/u%03d.ppm"%i) for i in range(num_imgs)]
In [223]:
from IPython.display import display, Image
from io import BytesIO
import PIL
def display_img_array(ima, cvt=None, **kwargs):
      if cvt is None and len(ima.shape)==3:
        cvt = cv2.COLOR_RGB2BGR
      if cvt:
          ima = cv2.cvtColor(ima, cvt)
      im = PIL.Image.fromarray(ima)
      bio = BytesIO()
      im.save(bio, format='png')
      display(Image(bio.getvalue(), format='png', **kwargs))
In [224]:
for i in range(num_imgs):
    try:
        display_img_array(imgs[i])
    except:
        print "error", i, imgs[i]
# since imgs[0] is not valid
imgs.pop(0)
error 0 None