def count_seeds(): img_src = request.args.get('img', type=str)#get the filename from the json request img_src = os.path.join(APP_STATIC, img_src)#get the full path of the image img = cv2.imread(img_src,cv2.CV_LOAD_IMAGE_COLOR) #read the image into a openCV image object contourList = im_proc.getContourListFrom(img, initValues=False) #find all the contours output = im_proc.drawContoursFromList(contourList)#draw the contours onto a copy of the original image seedList = list()#to hold the seed data seedListHeaders = ['Seed Number','Centroid','Seed Area','Length to Width','Circularity']#the headers for the statics table #iterate through the contour objects and get their statistics. These statistics are put into for key, cnt in contourList.iteritems(): featureList = list() cnt.getCentroid() featureList.append(cnt.getID()) featureList.append(cnt.getCentroid()) featureList.append(str(cnt.getArea())) cnt.getBoundingBox() boundingBoxDims = cnt.getMinBoundingBoxDimensions() featureList.append(round(cnt.getContourLengthToWidth(),2)) featureList.append(round(cnt.getHeywoodCircularity(),2)) seedList.append(featureList) filename = str(uuid.uuid4()) + ".jpg" #create random filename for the analysed image img_save_path = "app/static/uploads/analysed/" + filename #filepath for analysed image cv2.imwrite(img_save_path , output) #save the analysed image return jsonify(filename = filename, seedList = seedList, seedListHeaders = seedListHeaders)#pass jsonified data back to the client
import cv2 import sys import numpy as np from count_objects import im_proc from count_objects import contour_features as cf if len(sys.argv) != 2: ## Check for error in usage syntax print "Usage : python countSeeds.py <image_file>" else: #continue with the program ## Read image file in colour img = cv2.imread(sys.argv[1], cv2.CV_LOAD_IMAGE_COLOR) cList = im_proc.getContourListFrom(img, initValues=False) output = im_proc.drawContoursFromList(cList) ### show original im_proc.show_image('input', img) cv2.cv.MoveWindow('input', 0, 0) #Show final image im_proc.show_image('output', output) cv2.cv.MoveWindow('output', 500, 0) ## Wait for keystroke to allow user to see image displays cv2.waitKey(0) cv2.destroyAllWindows()
import cv2 import sys import numpy as np from count_objects import im_proc from count_objects import contour_features as cf if len(sys.argv)!=2: ## Check for error in usage syntax print "Usage : python countSeeds.py <image_file>" else:#continue with the program ## Read image file in colour img = cv2.imread(sys.argv[1],cv2.CV_LOAD_IMAGE_COLOR) cList = im_proc.getContourListFrom(img, initValues=False) output = im_proc.drawContoursFromList(cList) ### show original im_proc.show_image('input',img) cv2.cv.MoveWindow('input',0,0) #Show final image im_proc.show_image('output',output) cv2.cv.MoveWindow('output',500,0) ## Wait for keystroke to allow user to see image displays cv2.waitKey(0) cv2.destroyAllWindows()