opencv 遍历图片像素并生成新图片(两种方式对比)
来源:互联网 发布:美国 动画专业 知乎 编辑:程序博客网 时间:2024/05/17 06:13
由于图片尺寸过大,对图像进行resize处理用到的各种差值方法比较耗费时间,于是手动将图片缩小,每8*8个像素取一个点组成新的图片。主要考虑两种方式,第一种at方法取图像中的点的用法:image.at<uchar>(i,j):取出灰度图像中i行j列的点;image.at<Vec3b>(i,j)[k]:取出三通道图像中的某一通道对应的值。第二种(明显较为高效):image.ptr<uchar>(i)。
#include <stdio.h>#include <opencv.hpp>#include <cxcore.h>#include <iostream>using namespace cv;using namespace std;int main(){ double t = getTickCount(); Mat src = imread("test.bmp", 0); t = double(getTickCount() - t) * 1000 / getTickFrequency(); cout << "the load src pic time is " << t << "ms" << endl; //double t00 = getTickCount();//start //int nr = src.rows; //int nc = src.cols; //Mat img_src(cv::Size(nc / 8, nr / 8), CV_8U); //for (int i = 1; i < nr / 8; i++){ // for (int j = 1; j < nc / 8; j++){ // img_src.at<uchar>(i, j) = src.at<uchar>(8 * i , 8 * j); // } //} //t00 = double(getTickCount() - t00) * 1000 / getTickFrequency(); //cout << "the test time=" << t00 << "ms" << endl;//end ///*Mat img_src(cv::Size((nc + 1) / 3,(nr + 1) / 3),CV_8U); //for (int i=1; i < (nr + 1) / 3; i++){ // for (int j=1; j < (nc + 1) / 3; j++){ // img_src.at<uchar>(i, j) = src.at<uchar>(3 * i - 1, 3 * j - 1); // } //}*/ double t00 = getTickCount();//start int nr = src.rows; int nc = src.cols; Mat img_src(cv::Size(nc / 8, nr / 8), CV_8U); for (int i = 1; i < nr / 8; i++){ //取出原始图像中8*i行的指针,对应新的图像中的out指针 const uchar*inData = src.ptr<uchar>(8*i); uchar*outData = img_src.ptr<uchar>(i); for (int j = 1; j < nc / 8; j++){ outData[j] = inData[8*j]; } } t00 = double(getTickCount() - t00) * 1000 / getTickFrequency(); cout << "the test time=" << t00 << "ms" << endl;//end imshow("the resized img", img_src); //fast detect cornors //Mat src_copy = src.clone(); double t_fast = getTickCount(); vector<cv::KeyPoint>keypoints; cv::FastFeatureDetector fast(40, true); fast.detect(img_src, keypoints); drawKeypoints(img_src, keypoints, img_src, cv::Scalar::all(255), cv::DrawMatchesFlags::DRAW_OVER_OUTIMG); t_fast = double(getTickCount() - t_fast) * 1000 / getTickFrequency(); cout << "the fast detect corners time = " << t_fast << "ms" << endl; cout << "the keypoints size=" << keypoints.size() << endl; //resize(src, src, cv::Size(0.5*src.cols, 0.5*src.rows)); imshow("corners", img_src); waitKey();}
第一种image.at(i,j):用时431ms。
第二种image.ptr(i):用时9.6ms。
0 0
- opencv 遍历图片像素并生成新图片(两种方式对比)
- openCV遍历图片像素方式的时间效率对比
- OpenCV遍历图片像素点
- OpenCV入门三:OpenCV创建新图像以及遍历图片像素值和设置像素值
- OpenCV-Mat方式的获取图片的像素(一)
- OpenCV-Mat方式获取图片的像素(二)
- opencv学习(四)之像素遍历三种方式
- OpenCV读取图片并对比(可窗口显示)
- No 52 · 对比两张图片像素 返回bool
- 两幅图片逐个像素对比筛选不同的区域
- 像素对比两张图片相似度是否一样
- Picasso和Glide两种加载图片方式对比
- iOS 遍历图片每个像素点并修改rgb值
- c++ opencv读取图片像素值并进行加密
- OpenCV 中读取一张图片的像素点,并显示
- 【opencv】获取图片某点像素值的两种方法
- Android中图片对比并生成对比图
- 生成图片验证码的两种实现方式
- //回溯法输出素数环
- 【Java语法】java中成员内部类内为什么不允许有任何静态声明搜索
- centos 编译 zeromq
- 【转】NGUI制作按钮图标
- 四则运算(带括号)的小程序
- opencv 遍历图片像素并生成新图片(两种方式对比)
- 使用友元函数实现用外部函数修改类内的私有数据成员
- Linux 驱动开发之内核模块开发(四)—— 符号表的导出
- Treasure the new start, freshmen!
- [HDU]ACM Steps-Chapter One-Section 1
- i-jetty-3.1编译小结
- 【OpenGL】000 Visual Studio 2015 搭建OpenGL环境
- Shortest Prefixes (POJ_2001) 字典树
- LeetCode - 2. Add Two Numbers