dagcilibili
dagcilibili

Reputation: 491

Displaying images in opencv like MATLAB

I am trying to use opencv to display simple images that are generated by specifying the intensities of each pixels like in Matlab. However, the result has gaps when I show (cf. figure below). Is there a way to show the images that does not show these gaps?

#include <stdlib.h>
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char** argv)
{
    n = 100;
    m = 400;
    cv::Mat image(n,m,CV_8UC1);
    for( int i = 0; i < m; i++ )
        image.at<int>(10,i) = 255;
    cv::namedWindow( "Display window", WINDOW_AUTOSIZE );
    // Show our image inside it.
    cv::imshow( "Display window", image );                   
    // Wait for a keystroke in the window
    cv::waitKey(0); 
    return 0;
}

Here is an example image

Upvotes: 0

Views: 168

Answers (1)

berak
berak

Reputation: 39806

if your Mat is CV_8UC1, you will have to use:

image.at<uchar>(10,i) // not int !

enter image description here

int n = 100;
int m = 400;
cv::Mat image(n,m,CV_8UC1);
for( int i = 0; i < m; i++ )
    image.at<uchar>(10,i) = 255;

Upvotes: 1

Related Questions