1.We will iterate through them via pointers so the total number of elements depends from this number.
我们用指针在每一个通道上迭代,因此通道数就决定了需计算的元素总数。
原话:We create an output image with the same size and the same type as our input. As you can see in theHow the image matrix is stored in the memory? section, depending on the number of channels we may have one or more subcolumns. We will iterate through them via pointers so the total number of elements depends from this number.
2.We’ll use the plainC [] operator to access pixels.
利用C语言的[]操作符,我们能简单明了地访问像素。
3.Then simply access the right items with the [] operator.
有了这些指针后,我们使用[]操作符,就能轻松访问到目标元素。
4.For moving the output pointer ahead we simply increase this (with one byte) after each operation:
为了让输出指针向前移动,我们在每一次操作之后对输出指针进行了递增(移动一个字节):
5.On the borders of the image the upper notationresults inexistent pixel locations (like minus one - minus one).
到了2.x之后在命名空间cv中又多了几个函数,getTickCount(),getTickFrequency(),getCPUTickCount(),此时仍然可以使用上面的C接口的函数,也可以使用这几个namespace cv中的函数,两次使用getTickCount(),然后再除以getTickFrequency(),不过需要注意的是这时计算出来的是以秒s为单位的时间,这个是与上面的带cv前缀的函数的不同,而要使用更精确的计时,就需要使用getCPUTickCount(),不过现代计算机CPU的频率会随着负载而变化所以没大有必要使用该函数,可以参看函数的介绍【Also, since a modern CPU varies the CPU frequency depending on the load, the number of CPU clocks spent in some code cannot be directly converted to time units. Therefore,getTickCount is generally a preferable solution for measuring execution time.】也就是使用getTickCount就足够了。
10.changing the contrase and brightness of an image
// CCv.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include"cv.h"
#include"highgui.h"
using namespace cv;
using namespace std;
double alpha; /**<simple contrast control */
int beta; /**<simple brightness control */
int _tmain(int argc, _TCHAR* argv[])
{
Mat I,J;
I = imread(argv[1], CV_LOAD_IMAGE_UNCHANGED);
if (!I.data) return 0;
Mat new_image = Mat::zeros(I.size(), I.type());
//Initialize values
int dim = I.channels();
alpha = 2.2; /**<simple contrast control */
beta = 50;
//Do the operation new_image(i,j) = alpha * image(i,j) + beta
/*for (int y = 0; y < I.rows; y++)
{
for (int x = 0; x < I.cols; x++)
{
for (int c = 0; c < dim; c++)
{
new_image.at<Vec3b>(y,x)[c] = saturate_cast<uchar>(alpha * (I.at<Vec3b>(y,x)[c]) + beta);
}
}
}*/
I.convertTo(new_image,-1,alpha,beta);
namedWindow("origin", 1);
namedWindow("transform",1);
imshow("origin",I);
imshow("transform", new_image);
cvWaitKey(0);
return 0;
}
void ellipse(Mat &img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar&color, int thickness=1, int lineType=8, int shift=0)¶
Parameters:
img – Image.
center – Center of the ellipse.
axes – Length of the ellipse axes.
angle – Ellipse rotation angle in degrees.
startAngle – Starting angle of the elliptic arc in degrees.
endAngle – Ending angle of the elliptic arc in degrees.
box – Alternativeellipse representation via RotatedRect or CvBox2D. This means that the function draws an ellipseinscribed in the rotated rectangle.
color – Ellipse color.
thickness – Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that a filled ellipse sector is to be drawn.
lineType – Type of the ellipse boundary. See the line() description.
shift – Number of fractional bits in the coordinates of the center and values of axes.
C++:void
fillPoly(Mat &
img, const Point**
pts, const int*
npts, int
ncontours, const Scalar&
color, int
lineType=8, int
shift=0, Point
offset=Point()
)
Parameters:
img – Image.
pts – Array of polygons where each polygon is represented as an array of points.
npts – Array of polygon vertex counters.
ncontours – Number of contours that bind the filled region.
color – Polygon color.
lineType – Type of the polygon boundaries. See the line() description.
shift – Number of fractional bits in the vertex coordinates.
The function fillPoly fills an area bounded by several polygonalcontours. The function can fill complex areas, for example, areas with holes, contours with self-intersections (some of thier parts), and so forth.