nestvur.blogg.se

Divide photo into grid
Divide photo into grid








divide photo into grid

I've tried this code to demonstrate the techinque as well as solve your problem. From that technique you can totally solve your problem step by step.

divide photo into grid

import cv2Ĭv2.rectangle(im, (x, y), (x1, y1), (0, 255, 0))Ĭv2.imwrite("save/" + str(x) + '_' + str(y)+". Using background-position is a very well-known way to divide some image into small pieces. One possible way is to use both x and y to generate a unique name.įollowing is a working code with all of the above-mentioned issues fixed. Unique names are required for saving all the sub-images. The shape member of numpy array contains image height at first index and width at second index.Ī usual convention used for the naming convention is that M is the number of rows or height of the image while N is the number of columns or width of the image.Īnother problem is that not all the sub-images are being saved because names are assigned using y variable only which eventually overwrites the existing images due to repetition of y. There is a bit of confusion which I guess is caused by how numpy handles image dimensions and coordinates using the (row, column) convention and how OpenCV handles them using (x, y) convention. Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java.










Divide photo into grid