Hi all, Expect to see me here a bit in the next few weeks, working on my university honours project. I'm rewriting a C++ script using OpenCV that I made a year ago but this time in Python.
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
image = cv.imread('/home/pi/Desktop/ScannerDev/TestImage.png', cv.IMREAD_GRAYSCALE)
#ret, discrImage = cv.threshold(image,127,255,0)
def imageToPoints (image):
discrImage = cv.threshold (image, 127, 255, 0)
# Add a line of white values along the top of the image.
# This ensure that the binary outside contour generation works.
# It is removed later before points are written to point cloud.
for x in range (discrImage.cols):
# Set image x,0 = 255
discrImage[x,0] = [255,255,255]
return discrImage
while (1):
discrImage = imageToPoints (image)
cv.imshow ('original', image)
cv.imshow ('thresholded', discrImage)
k = cv.waitKey(5) & 0xFF
if k == 27:
break
cv.destroyAllWindows()
At the moment I'm working back up from examples online. It seems to all work fine up to this section:
# Add a line of white values along the top of the image.
# This ensure that the binary outside contour generation works.
# It is removed later before points are written to point cloud.
for x in range (discrImage.cols):
# Set image x,0 = 255
discrImage[x,0] = [255,255,255]
For some reason discrimage.cols and discrimage.width don't seem to work. I get the following printout:
Traceback (most recent call last):
File "I2LTEST3.py", line 21, in <module>
discrImage = imageToPoints (image)
File "I2LTEST3.py", line 14, in imageToPoints
for x in range (discrImage.cols):
AttributeError: 'tuple' object has no attribute 'cols'
Any ideas? Thanks!