Exemplo n.º 1
0
	def query():
		# create RemSensDB object (defined in RemoteSensingDB.py)
		dataset = RemSensDB()
		# create form
		form = ReusableForm(request.form)

		if request.method == "POST":
			"""
			process data
			if we find an error in filling out the form, it will print to the console
			"""
			try:
				searchType = request.form["radio"]
				if searchType == "Name":
					# if searching by name
					filename = request.form["name"]
					if not filename:
						raise AssertionError("Missing filename")
					# acquire this file from the database
					filestr = dataset.findByName(filename)
					if not filestr:
						raise AssertionError("Image not found")
					# convert db buffer image to a numpy array
					npimg = numpy.frombuffer(filestr, numpy.uint8)
					# convert numpy image to an opencv image
					img = cv2.imdecode(npimg, cv2.IMREAD_COLOR)
					# save the image to static/analyze.jpg for accessing later
					cv2.imwrite("static/analyze.jpg",img)
					
				elif searchType == "ID":
					# if searching by ID
					id_number = request.form["id_number"]
					if not id_number:
						raise AssertionError("Missing ID")
					# acquire this file from the database
					filestr = dataset.findByID(id_number)
					if not filestr:
						raise AssertionError("Image not found")
					# convert db buffer image to a numpy array
					npimg = numpy.frombuffer(filestr, numpy.uint8)
					# convert numpy image to an opencv image
					img = cv2.imdecode(npimg, cv2.IMREAD_COLOR)
					# save the image to static/analyze.jpg for accessing later
					cv2.imwrite("static/analyze.jpg",img)

				elif searchType == "File":
					# if uploading an image
					# get the uploaded file
					uploadFilename = request.files['file']
					if not uploadFilename:
						raise AssertionError("Missing File")
					# save the image to static/analyze.jpg for accessing later
					uploadFilename.save("static/analyze.jpg")
					
			except AssertionError as e:
				print("\n\n\n\n\n\n~~~~~\n{}\n~~~~~\n\n\n\n".format(e))
			# redirect to the analysis page
			return redirect(url_for('imagepage', imname="analyze"))
		return render_template('query.html', form=form)
Exemplo n.º 2
0
def uploadImage(img):
    data = RemSensDB()
    pass
Exemplo n.º 3
0
def getRandomImage():
    data = RemSensDB()
    r = Random()
    randNumber = r.randint(1, 5)
    return redirect("../image/{}".format(randNumber))
Exemplo n.º 4
0
def getImageByDate(date):
    data = RemSensDB()
    print(date)
    file = data.findByDate(date)
    return send_file(file, mimetype='image/jpg')
Exemplo n.º 5
0
def getImageList():
    data = RemSensDB()
    print("Listing\nImages")
    return "Listing\nImages"
Exemplo n.º 6
0
def getImageById(id_number):
    data = RemSensDB()
    file = findByID(id_number)
    filename = 'images/image{}.jpg'.format(id_number)
    return send_file(filename, mimetype='image/jpg')
Exemplo n.º 7
0
def basic():
    data = RemSensDB()
    return "<a href='/random'>hi</a>"