I have applied a threshold on a Region of Interest in a video frame. This seems to work perfectly, as the result looks like this:

threshold

I mark the ROI through a mouse callback function and then simply take the threshold via the following two lines of code:

ret_thresh, thresh = cv2.threshold(ROI, 80, 255, cv2.THRESH_BINARY)
    gray_frame[pt1[1]+3:pt1[1]+rect_height, pt1[0]+3:pt1[0]+rect_width] = thresh

, where pt1 is the upper left corner of the rectangle, and +3 is only to make sure I take the threshold of what's inside the rectangle and not on the border of the rectangle.

I have furthermore drawn a circular arch inside the wheel (as can be seen in the figure as well). This has been achieved through the code given in my other question.

Now, I am observing the points on a circular arch just below the arch that I have drawn. These points are within the threshold, so they should have values 0 or 255 only:

frameCount += 1
    currentTimestamp = timestamp + frameCount/fps 
    file = open("myFile.txt", "a+") 
    file.write(str(currentTimestamp))
    circleSegment = get_circle_segment(center_pt, 60, 72//2) #center_pt has been specified via mouse callback, radius is 60 px, radius of drawn arch is 70px
    for el in circleSegment: 
        pixel = gray_frame[el[1]][el[0]] #coordinates are (x,y). But accessing an image is always: first y-coordinates (rows) and then x-coordinates (columns)
        #log information
        file.write('\t' + str(pixel))
    file.write('\n')
    file.close()

The output txt-file does not contain any 0. But there are some empty spaces, so maybe that counts as 0 ?

4.033327383481244   255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
4.066660667642246   255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
4.099993951803248
4.13332723596425    255 255 255
4.166660520125252   255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
4.199993804286254   255 255 255 255 255 255 255 255 255 255 255 255 255

Also: when I add an error message whenever my frame-access has failed:

for el in circleSegment: 
        pixel = gray_frame[el[1]][el[0]]
        if pixel == False:
            print("Error")
        #log information

quite a few error messages are printed on my terminal. So, I assume there is something wrong with my image indexing. But I cannot really see the issue with this code.

0 Answers