Opencv.2.computer.vision.application.programming.cookbook--efficient scanning of continuous images

Source: Internet
Author: User

#include <opencv2\opencv.hpp>void colorreduce (cv::mat &image, int div=64) {  int nr= image.rows;//number of rows  int nc= image.cols * image.channels ();//total number of elements per line  if (image.iscontinuous ())  {  //Then no padded pixels  nc= nc*nr;   Nr= 1;  It is now a 1D array  }  int n= static_cast<int> (log (static_cast<double> (div))/log (2.0));  Mask used to round the pixel value  uchar mask= 0xff<<n;//e.g. for div=16, mask= 0xF0 for  (int j=0; j& LT;NR; J + +) {  uchar* data= image.ptr<uchar> (j);  for (int i=0; i<nc; i++) {  *data++= *data&mask + div/2;  }//End of Row                   }  }  int main (int a rgc,char* argv[]) {Cv::mat pimg;pimg=cv::imread ("lena.jpg"); Cv::imshow ("Image", pImg); Colorreduce (PIMG); cv::imshow ("PIMG", pImg); Cv::waitkey (0); return 0;}



Mat::reshape
Change the shape and number of channels or one of the 2D matrices without duplicating data.
C + +: Mat mat::reshape (int cn, int rows=0) const
Parameters:
CN-Keying the number of new channels. If cn=0, then the number of channels will remain unchanged.
rows– the new number of rows. If rows = 0, then the number of rows remains the same.

if (image.iscontinuous ()) {image.reshape (1,image.cols*image.rows);} int nr= image.rows; Number of rows  int nc= image.cols * image.channels ();//total number of elements per line  
The same effect as above!

Opencv.2.computer.vision.application.programming.cookbook--efficient scanning of continuous images

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.