opencv.zip

时间:2022-10-09 14:20:52
【文件属性】:

文件名称:opencv.zip

文件大小:838B

文件格式:ZIP

更新时间:2022-10-09 14:20:52

ma

#include #include using namespace std; using namespace cv; void mothed_1(Mat ℑ); void mothed_2(Mat ℑ); void mothed_3(Mat ℑ); int main(int argc, char** argv) { Mat src = imread("D:/images/bg_02.jpg"); if (src.empty()) { printf("could not load image...\n"); return -1; } namedWindow("input", WINDOW_AUTOSIZE); imshow("input", src); mothed_1(src); waitKey(0); return 0; } void mothed_1(Mat ℑ) { double t1 = getTickCount(); int w = image.cols; int h = image.rows; for (int row = 0; row < h; row++) { for (int col = 0; col < w; col++) { Vec3b bgr = image.at(row, col); bgr[0] = 255 - bgr[0]; bgr[1] = 255 - bgr[1]; bgr[2] = 255 - bgr[2]; image.at(row, col) = bgr; } } double t2 = getTickCount(); double t = ((t2 - t1) / getTickFrequency()) * 1000; ostringstream ss; ss << "Execute time : " << std::fixed << std::setprecision(2) << t << " ms "; putText(image, ss.str(), Point(20, 20), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(0, 0, 255), 2, 8); imshow("result", image); } void mothed_2(Mat ℑ) { double t1 = getTickCount(); int w = image.cols; int h = image.rows; for (int row = 0; row < h; row++) { Vec3b* curr = image.ptr(row); for (int col = 0; col < w; col++) { Vec3b bgr = curr[col]; bgr[0] = 255 - bgr[0]; bgr[1] = 255 - bgr[1]; bgr[2] = 255 - bgr[2]; } } double t2 = getTickCount(); double t = ((t2 - t1) / getTickFrequency()) * 1000; ostringstream ss; ss << "Execute time : " << std::fixed << std::setprecision(2) << t << " ms "; putText(image, ss.str(), Point(20, 20), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(0, 0, 255), 2, 8); imshow("result", image); } void mothed_3(Mat ℑ) { double t1 = getTickCount(); int w = image.cols; int h = image.rows; for (int row = 0; row < h; row++) { uchar* uc_pixel = image.data + row*image.step; for (int col = 0; col < w; col++) { uc_pixel[0] = 255 - uc_pixel[0]; uc_pixel[1] = 255 - uc_pixel[1]; uc_pixel[2] = 255 - uc_pixel[2]; uc_pixel += 3; } } double t2 = getTickCount(); double t = ((t2 - t1) / getTickFrequency()) * 1000; ostringstream ss; ss << "Execute time : " << std::fixed << std::setprecision(2) << t << " ms "; putText(image, ss.str(), Point(20, 20), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(0, 0, 255), 2, 8); imshow("result", image); }


【文件预览】:
mat_demo.cpp

网友评论

相关文章