How to divide an image horizontally into two equal parts.

asked 2018-08-07 20:11:05 -0600

ggrayce gravatar image

I try this, but i don't now how i show the result. i don't now what is the output of the function Rect(). Can someone help me?

The code is:

#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"

#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>

    using namespace cv;


int main()
{
Mat src = imread("melanoma_abertura.png", CV_LOAD_IMAGE_UNCHANGED);

//Mat top = topROI;


// imageInit should be a single-channel Mat
cv::Rect topROI(0, 0, src.cols, src.rows / 2);  //topo  - parte de cima da imagem
cv::Rect bottomROI(0, topROI.height, src.cols, src.rows - topROI.height);  //fundo - parte de baixo da imagem

//Rect_(_Tp _x, _Tp _y, _Tp _width(largura), _Tp _height(altura) );
// 0: é o topo x;
// y: é igual  a altura da primeira metade (topROI)
// width(largura): src.cols (colunas da imagem) - largura
// height(altura) : linhas da imagem - atura topROI

//int whitePixelsTop = cv::countNonZero(src(topROI));
//int whitePixelsBottom = cv::countNonZero(src(bottomROI));

Mat rectangle(src, bottomROI);

imshow("img cortada horizontalmente", bottomROI);  // ERROR!!

waitKey(0);



return 0;
}
edit retag flag offensive close merge delete

Comments

imshow("img cortada horizontalmente", rectangle);

sturkmen gravatar imagesturkmen ( 2018-08-08 01:13:07 -0600 )edit
1

@ggrayce don't use rectangle as a variable name there is already a function rectangle in opencv

LBerger gravatar imageLBerger ( 2018-08-08 02:58:07 -0600 )edit