Computer Vision News - September 2016

We will update the above code by splitting it into two separate functions, each performing one independent process: (a) getEdges for computing the images edges; and then (b) getHoughlines for extracting grid lines with the Hough transform method. The two functions will now be: Doing so would allow us, in the development process, to update/change one part of the code without changing all of it. Specifically, if we want to have a different edge detection method, we can replace it without touching the Hough method (getHoughlines) and vice versa, as these are now two independent processes in the graph. The TensorFlow code for executing this two-operation graph is as follows: Lines 2 and 3, in the above code, are a pipeline of two functions: the getEdges (line 2) computes the image’s edges and those are fed into the getHoughlines (line 3). The session.run() function executes the ‘X2’ which is a symbol for the getHoughlines. The TensorFlow “understands” this pipeline and it first executes the getEdges to get its output for the getHoughlines function. It is worth noting that TensorFlow has a powerful feature for visualizing the graph: it can help you understand and debug it. To visualize the graph, call the SummaryWriter function at the end of the “ with ” section in the code. Computer Vision News Tool 15 Tool “ It’s more than a deep learning package, it’s an architecture ” # Hough transformation for straight lines def getHoughLines(edges ): edges = np.squeeze(edges) lines = cv2.HoughLines(edges,1.0, np.pi / 180, 200) return lines # The canny edge detection def getEdges(img ): image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = cv2.convertScaleAbs(image) edges = cv2.Canny(gray, 10, 150, apertureSize=3) return edges 1. my_img = tf.placeholder(tf.float32, shape=shape, name='data') 2. X1 = tf.py_func(getEdges, [my_img], [tf.uint8], name='Edges') 3. X2 = tf.py_func(getHoughlines, [X1], [tf.float32], name='Hough') 4. raw_image_data = cv2.imread('dave.png') 5. with tf.Session() as session: 6. session.run(tf.initialize_all_variables()) 7. lines = session.run(X2, feed_dict={my_img: raw_image_data})[0] with tf.Session() as session: . . . tf.train.SummaryWriter('/tmp/log', session.graph)

RkJQdWJsaXNoZXIy NTc3NzU=