0

I'm trying to select the roi offset in a image in opencv 4.2, but i don't get it working. (I'm doing a recognition in the roi and want to mark it with a line in the original image.)

I thought that I could use on "roi" in the following code the locateROI() function but I get always the -> "AttributeError: 'numpy.ndarray' object has no attribute 'locateROI'".

import cv2
import numpy as np

img = cv2.imread('image.JPG',cv2.IMREAD_COLOR)
roi = img[10:200, 10:200]
roi.locateROI()

As help I used get Original image from ROI image in opencv

Anybody who ca help me?

f4bi4n
  • 13
  • 1
  • 4
  • Python OpenCV bindings don't use `cv::Mat`, instead they use numpy arrays. Hence, calling C++ member functions of the `Mat` class on those Python arrays is futile. I can't find a straightforward way to do the same in numpy -- the closes I've found so far is doing something like `np.byte_bounds(roi)[0] - np.byte_bounds(roi.base)[0]` to get a byte offset of the first element of the view relative to the first element of the parent array. You still have to do some simple math to handle multiple dimensions. – Dan Mašek Jan 12 '20 at 17:29
  • However, in the example above, you already know the position of the ROI, since you explicitly stated it when creating it. Easiest would be just to store those parameters into a variable and use them when necessary. – Dan Mašek Jan 12 '20 at 17:31
  • Okay, thanks! I will try it this way. I have already expected that the locateROI etc. methods are not available because I haven't found them in any docs from numpy. – f4bi4n Jan 12 '20 at 18:42

0 Answers0