Ask Your Question
0

openCv - C++ to python

asked 2018-10-17 16:53:40 -0600

Caseguy gravatar image

is there anyway to convert this out.at<uchar>(r, c) = src.at<uchar>(r1, c1); into python

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-10-17 18:18:15 -0600

sjhalayka gravatar image
#import opencv library
import cv2
import numpy

frame = cv2.imread('dove.png')

if frame is None:
    print('Error loading image')
    exit()

frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

for j in range(0, frame.shape[0]):
    for i in range(0, frame.shape[1]):
        g = frame[j, i]
        frame[j, i] = 255

cv2.imshow('frame', frame)
cv2.waitKey(0)
edit flag offensive delete link more

Comments

The code you have made makes a total white image.

The code that i tried to convert to python is this which will help shear and image. Would like to know if you are familiar with it ? http://answers.opencv.org/question/21...

Caseguy gravatar imageCaseguy ( 2018-10-18 00:38:59 -0600 )edit
1

@sjhalayka coded was good one. In C++

out.at<uchar>(r, c) = src.at<uchar>(r1, c1)

to Python

out(r, c) = src(r1, c1)
supra56 gravatar imagesupra56 ( 2018-10-18 07:42:49 -0600 )edit

The code is not mine but the only lines that i do not understand was the

out.at<uchar>(r, c) = src.at<uchar>(r1, c1)
 Mat out = Mat::ones(src.rows+maxYOffset, src.cols+maxXOffset, src.type());
Caseguy gravatar imageCaseguy ( 2018-10-18 07:48:16 -0600 )edit

What i have done so far in python to make image shear: https://pastebin.com/unjgzLh4 , i can see that the shear point have changed, but i really don't know how to apply it to the image :/

Caseguy gravatar imageCaseguy ( 2018-10-18 07:50:43 -0600 )edit
1

@Caseguy. Apologised. It is not right out(r, c) = src(r1, c1). I do not have it with me. I will try to find my file.

supra56 gravatar imagesupra56 ( 2018-10-18 08:14:36 -0600 )edit

Im so despret right now, i really wana do this, but my mind cant comprehend it :(. Trying to copy paste but that does not work either because i do not understand opencv on c++

Caseguy gravatar imageCaseguy ( 2018-10-18 08:17:59 -0600 )edit
1

In cpp:

out.at<uchar>(r, c) = src.at<uchar>(r1, c1)

in Python:

out[r, c] = src[r1, c1]

The r1 and c1 is same as j, i as @sjhalayka posted the code as above. Btw, I'm on offline for a week.

supra56 gravatar imagesupra56 ( 2018-10-18 09:44:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-10-17 16:53:40 -0600

Seen: 253 times

Last updated: Oct 17 '18