Hi, I’ve got an image as attached. I would like to crop it from left to right (width). I would like to crop the barcode and numbers
I tried something like this:
- convert to grayscale,
- crop all pixels that value is greater than threshold
This approach doesn’t work well. Any sugestions?
image = img height = image.shape width = image.shape TRESHOLD = 253 left_pos = 0 right_pos = 0 for i in range(height): for j in range(width): if (image[i][j] > TRESHOLD): if left_pos == 0: left_pos = j if right_pos < j: right_pos = j print("Leftpos: ",left_pos) print("rightpos: ",right_pos) crop_image = image[0:height, left_pos:right_pos] cv2.imwrite('result.jpg', crop_image) # result image