Skip to content

Instantly share code, notes, and snippets.

@hG3n
Last active November 26, 2015 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hG3n/ac0b845a3f9db2a198d9 to your computer and use it in GitHub Desktop.
Save hG3n/ac0b845a3f9db2a198d9 to your computer and use it in GitHub Desktop.
bachelor snippet
#!/usr/bin/env python
import sys
import numpy as np
import cv2 as cv
class Subimage:
def __init__(self, TL, BR):
self.tl = TL
self.br = BR
_x = BR[0] - TL[0]
_y = BR[1] - TL[1]
self.center_point = (_x,_y)
def draw(self, IMAGE):
cv.rectangle(IMAGE, self.tl, self.br, (0,255,0), 1)
def main():
num_subdivisions = 9
img = cv.imread('img.jpg')
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
img_rows = img.shape[0]
img_cols = img.shape[1]
img_rows_segment = img_rows / num_subdivisions
img_cols_segment = img_cols / num_subdivisions
subimage_container = []
for r in range(num_subdivisions):
for c in range(num_subdivisions):
tl_x = int(r * img_cols_segment)
tl_y = int(c * img_rows_segment)
br_x = int(r * img_cols_segment + img_cols_segment)
br_y = int(c * img_rows_segment + img_rows_segment)
subimage_container.append( Subimage((tl_x,tl_y) , (br_x,br_y)) )
img = cv.cvtColor(img, cv.COLOR_GRAY2RGB)
for i in subimage_container:
i.draw(img)
cv.imshow('foo',img)
cv.waitKey()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment