if (image.isContinuous()) { nc= nc*nl; nl= 1;
来源:互联网 发布:微擎 ecshop 数据同步 编辑:程序博客网 时间:2024/05/02 00:13
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include <iostream>
#ifndef _DEBUG
#pragma comment(lib,"IlmImf.lib")
#pragma comment(lib,"libjasper.lib")
#pragma comment(lib,"libjpeg.lib")
#pragma comment(lib,"libpng.lib")
#pragma comment(lib,"libtiff.lib")
#pragma comment(lib,"zlib.lib")
#pragma comment(lib,"opencv_calib3d2411.lib")
#pragma comment(lib,"opencv_contrib2411.lib")
#pragma comment(lib,"opencv_core2411.lib")
#pragma comment(lib,"opencv_features2d2411.lib")
#pragma comment(lib,"opencv_flann2411.lib")
#pragma comment(lib,"opencv_gpu2411.lib")
#pragma comment(lib,"opencv_highgui2411.lib")
#pragma comment(lib,"opencv_imgproc2411.lib")
#pragma comment(lib,"opencv_legacy2411.lib")
#pragma comment(lib,"opencv_ml2411.lib")
#pragma comment(lib,"opencv_nonfree2411.lib")
#pragma comment(lib,"opencv_objdetect2411.lib")
#pragma comment(lib,"opencv_ocl2411.lib")
#pragma comment(lib,"opencv_photo2411.lib")
#pragma comment(lib,"opencv_stitching2411.lib")
#pragma comment(lib,"opencv_superres2411.lib")
#pragma comment(lib,"opencv_ts2411.lib")
#pragma comment(lib,"opencv_video2411.lib")
#pragma comment(lib,"opencv_videostab2411.lib")
#else
#pragma comment(lib,"zlibd.lib")
#pragma comment(lib,"IlmImfd.lib")
#pragma comment(lib,"libjasperd.lib")
#pragma comment(lib,"libjpegd.lib")
#pragma comment(lib,"libpngd.lib")
#pragma comment(lib,"libtiffd.lib")
#pragma comment(lib,"opencv_calib3d2411d.lib")
#pragma comment(lib,"opencv_contrib2411d.lib")
#pragma comment(lib,"opencv_core2411d.lib")
#pragma comment(lib,"opencv_features2d2411d.lib")
#pragma comment(lib,"opencv_flann2411d.lib")
#pragma comment(lib,"opencv_gpu2411d.lib")
#pragma comment(lib,"opencv_highgui2411d.lib")
#pragma comment(lib,"opencv_imgproc2411d.lib")
#pragma comment(lib,"opencv_legacy2411d.lib")
#pragma comment(lib,"opencv_ml2411d.lib")
#pragma comment(lib,"opencv_nonfree2411d.lib")
#pragma comment(lib,"opencv_objdetect2411d.lib")
#pragma comment(lib,"opencv_ocl2411d.lib")
#pragma comment(lib,"opencv_photo2411d.lib")
#pragma comment(lib,"opencv_stitching2411d.lib")
#pragma comment(lib,"opencv_superres2411d.lib")
#pragma comment(lib,"opencv_ts2411d.lib")
#pragma comment(lib,"opencv_video2411d.lib")
#pragma comment(lib,"opencv_videostab2411d.lib")
#endif
using namespace cv;
void colorReduce0(cv::Mat image, int div=64) {
int nl= image.rows; // number of lines
int nc= image.cols * image.channels(); // total number of elements per line
for (int j=0; j<nl; j++) {
// get the address of row j
uchar* data= image.ptr<uchar>(j);
for (int i=0; i<nc; i++) {
// process each pixel ---------------------
data[i]= data[i]/div*div + div/2;
// end of pixel processing ----------------
} // end of line
}
}
void colorReduce1(const cv::Mat &image, cv::Mat &imageOut,int div=64) {
int nl= image.rows; // number of lines
int nc= image.cols * image.channels(); // total number of elements per line
for (int j=0; j<nl; j++) {
// get the address of row j
const uchar* data= image.ptr<uchar>(j);
uchar* dataOut= imageOut.ptr<uchar>(j);
for (int i=0; i<nc; i++) {
// process each pixel ---------------------
dataOut[i]= data[i]/div*div + div/2;
// end of pixel processing ----------------
} // end of line
}
}
// Test 6
// using .ptr and * ++ and bitwise (continuous)
void colorReduce6(cv::Mat image, int div=64) {
int nl= image.rows; // number of lines
int nc= image.cols * image.channels(); // total number of elements per line
if (image.isContinuous()) {
// then no padded pixels
std::cout << "Image is continuous" << std::endl;
nc= nc*nl;
nl= 1; // it is now a 1D array
}
int n= static_cast<int>(log(static_cast<double>(div))/log(2.0) + 0.5);
// mask used to round the pixel value
uchar mask= 0xFF<<n; // e.g. for div=16, mask= 0xF0
for (int j=0; j<nl; j++) {
uchar* data= image.ptr<uchar>(j);
for (int i=0; i<nc; i++) {
// process each pixel ---------------------
*data &= mask;
*data++ += div>>1;
// end of pixel processing ----------------
} // end of line
}
}
int main(int argc, char** argv)
{
Mat img1 = imread("lena.jpg");
//Mat img2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
if(img1.empty() )
{
printf("Can't read one of the images\n");
return -1;
}
Mat img2=img1.clone();
Mat img3=img1.clone();
imshow("org", img1);
waitKey(0);
cv::Mat imageOut(img1.rows,img1.cols,img1.type());
colorReduce1(img1,imageOut ,64);
imshow("imageOut", imageOut);
waitKey(0);
colorReduce0(img1, 128);
// drawing the results
imshow("reduce128", img1);
colorReduce0(img2, 64);
// drawing the results
imshow("reduce64", img2);
waitKey(0);
colorReduce6(img3);
imshow("colorReduce6", img3);
waitKey(0);
return 0;
}
- if (image.isContinuous()) { nc= nc*nl; nl= 1;
- nl
- nc
- nc
- NC
- NC
- nc
- nc
- nc
- kernel <==> user via nl
- nl命令
- nl命令
- nl命令
- nl命令
- nl命令
- nl命令
- nl命令
- linux ---- nl
- 往github上面提交项目
- C++中this指针的理解和用法
- eclipse -- 手把手教你如何把java代码,打包成jar文件以及转换为exe可执行文件
- 勾股定理一日一证连载38
- Tomcat7.0安装配置详细(图文)
- if (image.isContinuous()) { nc= nc*nl; nl= 1;
- Java连接MySQL数据库
- 用new动态创建结构体
- HDU 2846 字典树变形
- 一张图看清Map、Filter、Reduce
- hbase安装指南
- cas单节点登陆
- PGRouting初探
- 用 React.js 写一个最简单的 To-do List 应用