def test_slice_array(self): tablename = "Profiles_060_WTH" start = 1369753484783000 end = 1369753489783000 gate = 2500 con = db.connect("cube", "cube", "HDCP2") im = image.get_image_strip(con, tablename, start, end) #print im im_a = create_opencv_image_from_stringio(im["image"]) #print im_a #cv2.imwrite("./b.png", im_b) im_b = cv2.imread("img/b.png") im_new = [] for item in im_b: tmp = [] for unit in item: tmp.append(unit[0]) im_new.append(tmp) im_b = np.asarray(im_new) self.assertEqual(0, mse(im_a, im_b))
import os.path sys.path.append( os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) from radar import db, image import cv2 import numpy as np def create_opencv_image_from_stringio(img_stream, cv2_img_flag=1): img_stream.seek(0) img_array = np.asarray(bytearray(img_stream.read()), dtype=np.uint8) return cv2.imdecode(img_array, cv2_img_flag) tablename = "Profiles_060_WTH" # 5 secs start = 1369753484783000 end = 1369753489783000 #gate = 2500 con = db.connect("cube", "cube", "HDCP10") im= image.get_image_strip(con, tablename, start, end) im_a = create_opencv_image_from_stringio(im["image"]) print im["first"], im["last"] cv2.imwrite("./test.png", im_a)