Difference between revisions of "OpenCV/ImageProcessing/ExtractChannel"
From ProgrammingExamples
< OpenCV
Daviddoria (Talk | contribs) (Created page with "You will want to make sure that you include the imgproc, highgui, and core, libraries in your project settings. ==ExtractChannel.cpp== <source lang="cpp"> #include "highgui.h...") |
(No difference)
|
Latest revision as of 09:02, 15 May 2015
You will want to make sure that you include the imgproc, highgui, and core, libraries in your project settings.
ExtractChannel.cpp
#include "highgui.h" // required for imread() #include "cv.h" #include <iostream> #include <vector> int main(int, char*argv[]) { cv::Mat image = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR); if(image.empty()) { std::cout << "Can't read the image" << std::endl; return -1; } std::vector<cv::Mat> channels; cv::split(image, channels); cv::Mat r_channel = channels[0]; for(int i=0; i < r_channel.rows; i++) { for(int j=0; j < r_channel.cols; j++) { std::cout << r_channel.at<uchar>(i,j) << std::endl; } } return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(ExtractChannel) FIND_PACKAGE(OpenCV REQUIRED ) INCLUDE_DIRECTORIES( ${OPENCV_INCLUDE_DIR} ) ADD_EXECUTABLE(ExtractChannel ExtractChannel.cpp) TARGET_LINK_LIBRARIES(ExtractChannel ${OpenCV_LIBS})