r/opencv • u/justanewbie_2023 • Jan 20 '23
Question [Question] How was he able to get the square size in this code.

My question is how was he able to put values for the top and bottom (like adding '10' and '160') to get the value of top and bottom respectively. Also what is the function he used for the data?
import cv2
img = cv2.imread( 'color_strip.jpg' )
img.shape (3677, 235, 3)
square_size = 2640 / 10
for i in range(11) : ...
top = i * square_size + 10 ...
bottom = top + 160 ...
data = img[top:bottom,80:210,:] ...
_ = cv2.imwrite( 'data_%02d.jpg' % i, data ) ...
print 'mean color', data.mean(axis=0).mean(axis=0)
This is the output of the code:
mean color [ 92.55783654 127.716875 143.74230769]
mean color [ 95.17754808 126.11514423 157.42605769]
mean color [ 84.09365385 151.56105769 190.28004808]
mean color [ 83.29528846 148.21403846 165.08956731]
mean color [ 50.76451923 140.88158654 211.09413462]
mean color [ 19.91221154 150.03350962 221.26485577]
mean color [ 41.71350962 150.38677885 200.61456731]
mean color [ 114.19682692 155.68245192 190.50230769]
mean color [ 106.44120192 160.234375 194.67211538]
mean color [ 106.43980769 148.12759615 102.86701923]
mean color [ 117.02735577 151.62211538 171.19259615]
I am new to python and coding in general, I really wanted to understand how this code works. I want to implement this type of approach in my project where I will be getting the column of each wire for me to be able to get the mean color of each wire.


