D-Alex / ropencv

ffi ruby wrapper for opencv
Other
67 stars 14 forks source link

Translating Mat#at from C++ #8

Closed nicholasjhenry closed 10 years ago

nicholasjhenry commented 10 years ago

I'm trying to translate the last three lines in the snippet below from C++ to Ruby. Any help would be much appreciated. Thank you!

 cv::Mat image= cv::imread("boldt.jpg");

int i= rand()%image.cols;
int j= rand()%image.rows;

# Set the value to white
image.at<cv::Vec3b>(j,i)[0]= 255;
image.at<cv::Vec3b>(j,i)[1]= 255;
image.at<cv::Vec3b>(j,i)[2]= 255;
nicholasjhenry commented 10 years ago

I found that I can set a value using Mat#set(i, j, val)[1]. How do I set the individual channels in RGB?

[1] https://github.com/D-Alex/ropencv/blob/master/lib/ropencv/ropencv_ruby.rb#L425

D-Alex commented 10 years ago

Currently there are two ways to access a multi channel mat from ruby

I pushed a modified version of mat[],mat[]=,set(),at() to master supporting multiple channels

nicholasjhenry commented 10 years ago

Thank you for the suggestions and modification. Very helpful!