Added a section on accessing matrix elements
authorVictor Erukhimov <no@email>
Wed, 12 Jan 2011 18:35:55 +0000 (18:35 +0000)
committerVictor Erukhimov <no@email>
Wed, 12 Jan 2011 18:35:55 +0000 (18:35 +0000)
doc/opencv_user.pdf
doc/user_mat.tex

index 1b72ddad533f657fa3eceff70b064440c1491867..2606e815ddae468230f078c6493544d16325a27b 100644 (file)
Binary files a/doc/opencv_user.pdf and b/doc/opencv_user.pdf differ
index 731e7b0a473cbdd5414deb8e22677f030bf188fe..323f612e0931deb4075942c1130f1eed49940fae 100644 (file)
@@ -33,11 +33,37 @@ Scalar intensity = img.at<uchar>(x, y);
 
 Now let us consider a 3 channel image with \texttt{bgr} color ordering (the default format returned by imread):
 \begin{lstlisting}
-Scalar intensity = img.at<uchar>(x, y);
+Vec3b intensity = img.at<Vec3b>(x, y);
 uchar blue = intensity.val[0];
 uchar green = intensity.val[1];
 uchar red = intensity.val[2];
 \end{lstlisting}
+
+You can use the same method for floating-point images (for example, you can get such an image by running Sobel on a 3 channel image):
+\begin{lstlisting}
+Vec3f intensity = img.at<Vec3f>(x, y);
+float blue = intensity.val[0];
+float green = intensity.val[1];
+float red = intensity.val[2];
+\end{lstlisting}
+
+The same method can be used to change pixel intensities:
+\begin{lstlisting}
+img.at<uchar>(x, y) = 128;
+\end{lstlisting}
+
+There are functions in OpenCV, especially from calib3d module, such as \texttt{projectPoints}, that take an array of 2D or 3D points in the form of \texttt{Mat}. Matrix should contain exactly one column, each row corresponds to a point, matrix type should be 32FC2 or 32FC3 correspondingly. Such a matrix can be easily constructed from std::vector:
+\begin{lstlisting}
+vector<Point2f> points;
+//... fill the array
+Mat _points = Mat(points);
+\end{lstlisting}
+One can access a point in this matrix using the same method \texttt{Mat::at}:
+\begin{lstlisting}
+Point2f point = _points.at<Point2f>(i, 0);
+\end{lstlisting}
+
+
 \fi