当前位置: 首页 > news >正文

兴宁区住房和城乡建设局网站宝塔wordpress打开卡顿

兴宁区住房和城乡建设局网站,宝塔wordpress打开卡顿,网站建设栏目,网页编辑岗位职责和任职要求目录1 图片处理1.1 显示图片1.2 旋转图片1.3 合并图片1.4、Mat类1.4.1、像素的储存结构1.4.2、访问像素数据1.6、rgb转灰度图1.7、二值化1.8、对比度和亮度1.9、图片缩放1.9.1、resize临近点算法双线性内插值1.9.2、金字塔缩放1.10、图片叠加1 图片处理 1.1 显示图片 #includ… 目录1 图片处理1.1 显示图片1.2 旋转图片1.3 合并图片1.4、Mat类1.4.1、像素的储存结构1.4.2、访问像素数据1.6、rgb转灰度图1.7、二值化1.8、对比度和亮度1.9、图片缩放1.9.1、resize临近点算法双线性内插值1.9.2、金字塔缩放1.10、图片叠加1 图片处理 1.1 显示图片 #include opencv2/core.hpp #include opencv2/imgcodecs.hpp #include opencv2/highgui.hppusing namespace cv;int main(int argc, char *argv[]) {Mat image imread(test.jpeg);namedWindow(img);imshow(img, image);waitKey(0); }1.2 旋转图片 旋转图片用的是rotate(InputArray src, OutputArray dst, int rotateCode)方法opencv提供了以下3种旋转方式。 enum RotateFlags {ROTATE_90_CLOCKWISE 0, //顺时针旋转90度ROTATE_180 1, //旋转180度ROTATE_90_COUNTERCLOCKWISE 2 //逆时针旋转90度 };#include opencv2/core.hpp #include opencv2/imgcodecs.hpp #include opencv2/highgui.hppusing namespace cv;int main(int argc, char *argv[]) {Mat src imread(test.jpeg);Mat dst;rotate(src, dst, ROTATE_90_CLOCKWISE); //顺时针旋转90度namedWindow(img);imshow(img, dst);waitKey(0); }1.3 合并图片 把两张图片合并到一张。 思路创建一个能容纳两张图片的Mat然后对左右两个区域分别填充像素。 #include opencv2/core.hpp #include opencv2/imgcodecs.hpp #include opencv2/highgui.hpp #include opencv2/imgproc.hppusing namespace cv;int main(int argc, char *argv[]) {Mat img1 imread(test1.jpeg);Mat img2 imread(test.jpeg);Mat dst;dst.create(img1.rows img2.rows ? img1.rows : img2.rows,img1.cols img2.cols, img1.type());Mat r1 dst(Rect(0, 0, img1.cols, img1.rows));img1.copyTo(r1);Mat r2 dst(Rect(img1.cols, 0, img2.cols, img2.rows));img2.copyTo(r2);namedWindow(img);imshow(img, dst);waitKey(0); }1.4、Mat类 opencv的Mat类对象可以用来存放图像的像素数据它有多种储存模式比较常用的有以下四种。 #define CV_8UC1 CV_MAKETYPE(CV_8U,1) #define CV_8UC2 CV_MAKETYPE(CV_8U,2) #define CV_8UC3 CV_MAKETYPE(CV_8U,3) #define CV_8UC4 CV_MAKETYPE(CV_8U,4)它们的含义可以根据名字来判别比如CV_8UC3代表一个像素由3个8位的uchar储存我们平时看到的rgb三色图就可以用这种类型来储存。 1.4.1、像素的储存结构 Mat对象的像素数据存放在一个char类型数据上成员名叫data。 以一张CV_8UC3类型、大小为2 * 2的图像为例它对应的储存结构可以以下图表示。 在显示图像时映射成下图所示。 1.4.2、访问像素数据 从上一节我们可以看到像素数据里的红蓝绿数据是以蓝(0)绿(1)红(2)的顺序来排列的。比如我们要访问第一行第一列的绿色数据可以用mat.data[1]来访问访问第二行第一列的红色数据可以用mat.data[8]。 下面举例说明opencv修改像素数据的方式。 比如我们要用opencv来画一幅红蓝间条的图片可以用以下程序来实现。 #include opencv2/core.hpp #include opencv2/highgui.hppusing namespace cv;int main(int argc, char *argv[]) {Mat mat(400, 300, CV_8UC3); //创建一张400 * 300的图片int pixelSize mat.elemSize(); //单个像素的大小本例中大小为3int size mat.rows * mat.cols * pixelSize; //行*列*像素大小 缓存区大小for (int i 0; i size; i pixelSize) {/* 每隔十行切换一次颜色 */int row i / (mat.cols * pixelSize); if (row % 20 10) {/* 画蓝色像素点 */mat.data[i] 255;mat.data[i 1] 0;mat.data[i 2] 0;} else {/* 画红色像素点 */mat.data[i] 0;mat.data[i 1] 0;mat.data[i 2] 255;}}namedWindow(mat);imshow(mat, mat);waitKey(0); }opencv中除了用mat.data可以访问像素数据外还提供了几种访问方式如下表所示。 mat.step代表一行的大小即colSum * ps。 编号访问方式特点例子(访问第r行第c列的蓝色)1mat.data[index]遍历速度和访问速度都是最快的但使用不便。data[r * mat.step c 0]2mat.ptr(row, col)速度比第一种稍慢可以通过行号和列号来直接访问。mat.ptr(row, col)[0]3mat.at(row, col)速度最慢可以通过行号和列号来直接访问。mat.at(row, col)[0] 以上效率是用opencv3.4测得的不同版本的效率可能不一样。 测试例程 #include opencv2/core.hpp #include opencv2/highgui.hpp #include QDebug #include QElapsedTimerusing namespace cv;int main(int argc, char *argv[]) { // printMs();Mat mat(3000, 4000, CV_8UC3);int pixelSize mat.elemSize();QElapsedTimer timer;timer.start();for (int r 0; r mat.rows; r) {for (int c 0; c mat.cols; c) {int rowStep r * mat.step;int colIndex c * pixelSize ;mat.data[rowStep colIndex ] 0;//Bmat.data[rowStep colIndex 1] 255;//Gmat.data[rowStep colIndex 2] 0;//R}}qDebug() QString(%1: %2ms).arg(step).arg(timer.elapsed());timer.start();for (int r 0; r mat.rows; r) {for (int c 0; c mat.cols; c) {Vec3b *pixel mat.ptrVec3b(r, c);pixel-val[0] 0;//Bpixel-val[1] 255;//Gpixel-val[2] 0;//R}}qDebug() QString(%1: %2ms).arg(ptr).arg(timer.elapsed());timer.start();for (int r 0; r mat.rows; r) {for (int c 0; c mat.cols; c) {Vec3b pixel mat.atVec3b(r, c);pixel.val[0] 0;//Bpixel.val[1] 255;//Gpixel.val[2] 0;//R}}qDebug() QString(%1: %2ms).arg(at).arg(timer.elapsed());timer.start();auto it mat.beginVec3b(), end mat.endVec3b();for (; it ! end; it) {(*it).val[0] 0;//B(*it).val[1] 255;//G(*it).val[2] 255;//R}qDebug() QString(%1: %2ms).arg(it).arg(timer.elapsed());namedWindow(mat);imshow(mat, mat);waitKey(0); }step: 45ms ptr: 54ms at: 96ms it: 102ms1.6、rgb转灰度图 #include opencv2/core.hpp #include opencv2/imgcodecs.hpp #include opencv2/highgui.hpp #include opencv2/imgproc.hppusing namespace cv;int main(int argc, char *argv[]) {Mat img imread(test.jpeg);Mat gray;cvtColor(img , gray, COLOR_BGR2GRAY);namedWindow(gray);imshow(gray, gray);waitKey(0); } 1.7、二值化 二值化含义把灰度大于阀值的用白色显示小于阀值的像素用黑色显示。 opencv函数threshold(src, dst, thresh, maxval, type); #include opencv2/core.hpp #include opencv2/imgcodecs.hpp #include opencv2/highgui.hpp #include opencv2/imgproc.hppusing namespace cv;int main(int argc, char *argv[]) {Mat src imread(test.jpeg);Mat gray;Mat bin;cvtColor(src, gray, COLOR_BGR2GRAY);threshold(gray, bin, 100, 255, THRESH_BINARY); // threshold(gray, bin, 100, 255, THRESH_BINARY_INV);namedWindow(img);imshow(img, bin);waitKey(0);}1.8、对比度和亮度 对比度和亮度利用公式来计算g(i, j) a * f(i, j) b a代表对比度(1.0 ~ 3.0)b代表亮度(0 ~ 100)。 void myConvert(Mat src, Mat dst, float a, float b) {dst.create(src.rows, src.cols, src.type);for (int r 0; r src.rows; r) {for (int c 0; c src.cols; c) {for (int i 0; i 3; i) {/* saturate_castuchar限制表达式的结果最大为uchar的大小也就是255 */dst.atVec3b(r,, c)[i] saturate_castuchar(a * src.atVec3b(r, c)[i] b);}}} }opencv提供的接口是convertTo。 #include opencv2/core.hpp #include opencv2/imgcodecs.hpp #include opencv2/highgui.hpp #include opencv2/imgproc.hppusing namespace cv;int main(int argc, char *argv[]) {Mat src imread(test.jpeg);Mat dst;src.convertTo(dst, -1, 2.0, 50); //类型填负数代表与src一致namedWindow(img);imshow(img, dst);waitKey(0); }1.9、图片缩放 1.9.1、resize opencv为图片缩放提供了resize(src, dst, dsize, fx 0, fy 0, interpolation INTER_LINEAR)函数。 #include opencv2/core.hpp #include opencv2/imgcodecs.hpp #include opencv2/highgui.hpp #include opencv2/imgproc.hppusing namespace cv;int main(int argc, char *argv[]) {Mat src imread(test.jpeg);Mat dst;resize(src, dst, Size(300, 300), 0, 0, INTER_NEAREST);namedWindow(src);imshow(src, src);namedWindow(dst);imshow(dst, dst);waitKey(0); }resize的最后一个参数interpolation是缩放使用的算法类型opencv提供了以下几种算法。 enum InterpolationFlags{/** nearest neighbor interpolation */INTER_NEAREST 0,/** bilinear interpolation */INTER_LINEAR 1,/** bicubic interpolation */INTER_CUBIC 2,/** resampling using pixel area relation. It may be a preferred method for image decimation, asit gives moire-free results. But when the image is zoomed, it is similar to the INTER_NEARESTmethod. */INTER_AREA 3,/** Lanczos interpolation over 8x8 neighborhood */INTER_LANCZOS4 4,/** Bit exact bilinear interpolation */INTER_LINEAR_EXACT 5,/** mask for interpolation codes */INTER_MAX 7,/** flag, fills all of the destination image pixels. If some of them correspond to outliers in thesource image, they are set to zero */WARP_FILL_OUTLIERS 8,/** flag, inverse transformationFor example, #linearPolar or #logPolar transforms:- flag is __not__ set: \f$dst( \rho , \phi ) src(x,y)\f$- flag is set: \f$dst(x,y) src( \rho , \phi )\f$*/WARP_INVERSE_MAP 16 };下面对INTER_NEAREST(临近点算法)和INTER_LINEAR(双线性内插值)做介绍。 临近点算法 原理 特点速度最快会失真不够平滑。 双线性内插值 原理用像素点的临近四个点做平均计算。 特点速度稍慢一点平滑效果比临近点算法好但图像的边界的棱角会被平均而模糊掉。 1.9.2、金字塔缩放 opencv提供了向上重建(拉普拉斯金字塔放大)的pyrUp()和向下采样(高斯金字塔缩小)的pyrDown()可以比较好地还原图像特征它们无法指定放大的倍数只能成倍地放大或缩小比如1616的图片调用pyrUp就变为6464而调用pyrDown就变为4*4。 用法如下 #include opencv2/core.hpp #include opencv2/imgcodecs.hpp #include opencv2/highgui.hpp #include opencv2/imgproc.hppusing namespace cv;int main(int argc, char *argv[]) {Mat src imread(test.jpeg);Mat gdst; //高斯缩小Mat ldst; //拉普拉斯放大pyrDown(src, gdst);pyrUp(src, ldst);namedWindow(src);imshow(src, src);namedWindow(gdst);imshow(gdst, gdst);namedWindow(ldst);imshow(ldst, ldst);waitKey(0); }1.10、图片叠加 原理 dst src1 * a src2 * (1 - a) gamma; a代表透明度(0 ~ 1.0)gamma代表增益用来调整颜色深度。 opencv提供了addWeighted(src1, alpha, src2, beta, gamma, dst, dtype -1)函数可以用来叠加图片。 #include opencv2/core.hpp #include opencv2/imgcodecs.hpp #include opencv2/highgui.hpp #include opencv2/imgproc.hppusing namespace cv;int main(int argc, char *argv[]) {Mat src imread(test1.jpeg);Mat src2 imread(test.jpeg);Mat src1 src(Rect(0, 0, src2.cols, src2.rows)); //把在图一中截取图二相同大小的部分Mat dst;float a 0.5; //透明度addWeighted(src1, a, src2, 1 - a, 1, dst);namedWindow(blending);imshow(blending, dst);waitKey(0);}
http://www.dnsts.com.cn/news/23564.html

相关文章:

  • 网站建设策划范文流量宝
  • 上海建设网站的网站备案网站名怎么填写
  • 零基础可以学平面设计吗西安网站seo公司
  • 电子商务网站建设的体会大连市网站制作电话
  • 营销型网站的作用广告制作网站
  • 深圳营销型网站seo福田网站设计方案
  • vs2010网站开发实例广东省建设集团有限公司
  • 做网站公司哪个品牌好公众号商城
  • wordpress api.w.orgseo课程哪个好
  • 网站开发难不难网站做某个关键词排名该怎么做
  • 蚌埠做网站的公司哪家好中山建设网站
  • 做网站的公司好坑啊京津冀协同发展建议
  • php 企业网站源码公司网站维护如何上图
  • 淄博企业建网站wordpress数据库分离
  • 网站的框架东莞振安保安公司
  • 英文网站 字体大小深圳哪个招聘网站好
  • 县城做信息网站赚不赚钱wordpress++优化
  • 什么网站都能进的浏览器在演示文稿上网站怎么做
  • 乌兰察布盟建设银行网站做家居用品亚马逊看哪些网站
  • 平顶山住房和城乡建设厅网站wordpress 分页列表
  • 嘉定专业做网站wordpress中文404
  • 自己做网站需要什么技能做期货在哪个网站看消息
  • 如何快速搭建网站定制型网站 成功案例
  • 做pc端网站资讯网站子域名怎么设置
  • 做网站的如何找业务wordpress安全者
  • 现在大家做电商网站用什么源码江苏高效网站制作机构
  • 哪里有网站建设加工咨询类网站建设方案书
  • 网站开发周期做科技的网站
  • 局域网建设网站如何访问网页设计专业好找工作吗
  • 上海网站建设科技公司重庆建设工程造价管理协会