Ask Your Question

jonlwowski012's profile - activity

2020-04-30 19:52:06 -0600 received badge  Notable Question (source)
2019-03-04 20:44:50 -0600 received badge  Notable Question (source)
2018-08-20 09:31:18 -0600 received badge  Popular Question (source)
2018-05-29 07:50:37 -0600 received badge  Popular Question (source)
2016-01-10 13:14:29 -0600 received badge  Student (source)
2015-06-18 15:21:18 -0600 received badge  Self-Learner (source)
2015-06-18 12:26:04 -0600 asked a question Converting Python to C++

I have the following opencv code in python and I would like to convert it to c++. I have already converted lines 1 and 2, but I got stuck on lines 3 and 4. Do any of you know how to convert those lines to c++.

contours, hierarchy = cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
cnt = contours[0]
leftmost = tuple(cnt[cnt[:,:,0].argmin()][0])
rightmost = tuple(cnt[cnt[:,:,0].argmax()][0])
edge_left_x = leftmost[0]-320
edge_left_y = leftmost[1]-180
edge_right_x = rightmost[0]-320
edge_right_y = rightmost[1]-180
2015-06-18 12:22:50 -0600 answered a question Finding Leftmost and Rightmost Edge of Binary Image

I found out how to do it. I just followed this website's tutorials.

http://opencvpython.blogspot.com/2012...

2015-06-12 14:23:19 -0600 received badge  Supporter (source)
2015-06-12 12:39:43 -0600 asked a question Finding Leftmost and Rightmost Edge of Binary Image

I am trying to find the leftmost and rightmost edge of a binary image like the one attached. I am currently doing this by using a for loop starting from the center of the white portion and working towards a direction until I get to my first black pixel. This works great except it is very slow. Is there any other ways to do this, but in a faster way. Thanks all who reply.

Binary Image

#### Start Image Processing #########

hsv = cv2.cvtColor(cv_image, cv2.COLOR_BGR2HSV)
lower_red = np.array([0,100,100])
upper_red = np.array([10,255,255])
mask = cv2.inRange(hsv, lower_red, upper_red)
mat=cv.GetMat(cv.fromarray(mask))
moments=cv.Moments(mat)
yc_red= moments.m01/moments.m00
xc_red=moments.m10/moments.m00
width, height = cv.GetSize(mat)
max_right_red_x = 0
for a in range(int(round(xc_red)), width, 3):
     for b in range (0, height, 3):
        if(mat[b,a] == 0):
           continue
        elif(a > max_right_red_x):
           max_right_red_x = a
           max_right_red_y = b
max_left_red_x = width
for a2 in range(int(round(xc_red)), 0, -3):
     for b2 in range (0, height, 3):
        if(mat[b2,a2] == 0):
           continue
        elif(a2 < max_left_red_x):
           max_left_red_x = a2
           max_left_red_y = b2

### End of Image Processing ######