Ask Your Question

Revision history [back]

try this code to get something like

image description

if you uncomment //flip(horizontalImg, horizontalImg, 1); you will get something like image description

#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"

#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    Mat horizontalImg = imread(argv[1]);
    //flip(horizontalImg, horizontalImg, 1);
    Mat output = horizontalImg.t();

    copyMakeBorder(output, output, 0, 0, 0, output.rows - output.cols, BORDER_CONSTANT, Scalar(255, 255, 255));
    Rect rect(0, 0, horizontalImg.cols, horizontalImg.rows);
    Mat mask(horizontalImg.rows, horizontalImg.cols, CV_8UC1, Scalar(255));
    vector<Point> pts = { Point(0,0), Point(mask.rows,mask.rows), Point(0,mask.rows) };

    fillConvexPoly(mask, pts, Scalar(0));

    horizontalImg.copyTo(output(rect),mask);
    imshow("source", horizontalImg);

    imshow("final result", output);
    waitKey(0);

    return 0;
}

try this code to get something likelike the image below. ( it uses single image )

image description

if you uncomment //flip(horizontalImg, horizontalImg, 1);

you will get something like like the image below ( it seems more logical to me ) image description

#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"

#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    Mat horizontalImg = imread(argv[1]);
    //flip(horizontalImg, horizontalImg, 1);
    Mat output = horizontalImg.t();

    copyMakeBorder(output, output, 0, 0, 0, output.rows - output.cols, BORDER_CONSTANT, Scalar(255, 255, 255));
    Rect rect(0, 0, horizontalImg.cols, horizontalImg.rows);
    Mat mask(horizontalImg.rows, horizontalImg.cols, CV_8UC1, Scalar(255));
    vector<Point> pts = { Point(0,0), Point(mask.rows,mask.rows), Point(0,mask.rows) };

    fillConvexPoly(mask, pts, Scalar(0));

    horizontalImg.copyTo(output(rect),mask);
    imshow("source", horizontalImg);

    imshow("final result", output);
    waitKey(0);

    return 0;
}