#from opencv import highgui as hg
import cv
#capture = cd.CreateCameraCapture(0)
#image = cv.LoadImage('car.jpg')
image = cv.LoadImageM("car.jpg")
cv.NamedWindow("Snapshot")
#frame = hg.cvQueryFrame(capture)
#cv.ShowImage("Snapshot", image)


original = cv.LoadImageM("car.jpg",cv.CV_LOAD_IMAGE_GRAYSCALE)
binary_image = cv.CreateImage((image.width,image.height), 8, 1)
cv.Threshold(original, binary_image,128,255,cv.CV_THRESH_OTSU)

image2 = cv.CreateImage((2*image.width,image.height), 8, 1)
cv.SetImageROI(image2,(0,0,image.width,image.height))
cv.Copy(original,image2)

cv.SetImageROI(image2,(image.width,0,2*image.width,image.height))
cv.Copy(binary_image,image2)

cv.SetImageROI(image2,(0,0,2*image.width,image.height))
#cv.Copy(binary_image,image2)

cv.ShowImage("Snapshot",image2)
#cv.GetSubRect
#cv.CreateMat(image.height, image.width, cv.CV_32FC1)

#cv.ShowImage("Snapshot", binary_image)
myblobs = cv.CBlobResult(binary_image, mask,0, True)
# myblobs.filter_blobs(325,2000)
# blob_count = myblobs.GetNumBlobs()

# from tesseract import image_to_string
# image = open("blob.jpg")
# text = image_to_string(image)

cv.WaitKey(2000)