xs =  ys =  files = glob.glob ("./ sisaku-tra/*") for i, f in enumerate (files): img = cv2.imread (f) gray = cv2.cvtColor (img, cv2.COLOR_BGR2GRAY) ret, binary = cv2.threshold (gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU) kernel = cv2.getStructuringElement (cv2.MORPH_ELLIPSE, (5, 5)) binary = cv2.dilate (binary, kernel) contours, hierarchy = cv2.findContours (binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) target_contour = max (contours, key = lambda x: cv2.contourArea (x)) area = cv2.contourArea (target_contour) retval = cv2.arcLength (target_contour, True) ratio = area/retval xs.append (ratio) hsv = cv2.cvtColor (img, cv2.COLOR_BGR2HSV) h, s, v = cv2.split (hsv) v = v [10<v] value = v [v<225] .mean () ys.append (value) plt.scatter (xs, ys, s = 10) for i, (x, y) in enumerate (zip (xs, ys)): plt.annotate (str (i), (x, y), size = 5) plt.savefig ('plt1.jpg') Code
The above code gives a scatter plot like below
The order and point numbers stored in the sisaku-tra file are different.
Why is this?
Thank you for everyone.
Answer # 1
The order of the files obtained by
glob.globis clear and nothing is guaranteed.
Whether or not the results are sorted depends on the file system.
glob --- Unix-style pathname pattern expansion — Python 3.8.0 documentation
You say it will behave differently depending on the environment, it will return in the proper order, but that's it.
I can't figure out the situation, for example"There is no guarantee that you will get a list of files in that order even if they are neatly arranged in Explorer". I think there is a misunderstanding around that.
- python - connect the plotted points
- python 3x - how to count the number of data extracted by pandas or how to solve the error
- python 3x - i want to output the name corresponding to the number entered in the excel file
- i want to paint the vertices (contact points) of a figure with a specific shape from within a two-dimensional array created usin
- python - when you want to judge by the number of characters from the back with a regular expression
- python - how to get the number of searches for a specific word within the period
- python - sumy by specifying the maximum number of characters with sumy
- python - i want to add a line number to the data frame
- number of python combinations
- python - i want to divide a binary number into two, store it in a list, and represent it in a different decimal number
- python - valueerror: field'id' expected a number but got'suzukitadashi'
- i want to invert the number 12345 in python like 54321 and display it
- get the number of characters from the python text box
- get the total number and name of python grouping
- how to align the number of elements with overlaplengt of python etc
- set python excel serial number to date and time
- how to multiply each element by a number in a python 2d list
- where is the minor version number of python that starts by default specified?
- python - how to accept number input even if keypressevent is defined for qlineedit in pyside
- python - how to count the number of characters in a character string including a regular expression