Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv 由cvThreshold生成的奇怪的二值图像值_Opencv - Fatal编程技术网

Opencv 由cvThreshold生成的奇怪的二值图像值

Opencv 由cvThreshold生成的奇怪的二值图像值,opencv,Opencv,嘿,伙计们,我正在使用opencv做一些车辆识别工作,当我使用cvThershold将灰色图像转换为二值图像时,返回图像非常奇怪,二值图像假设只有两个值,0和255,但是,它包含其他值,如2,3254253,有人知道这是怎么发生的,而且cvCmps也有这个问题。cvThreshold有各种超出正常二进制阈值的行为。它们在本节中进行了描述 例如,如果使用标志threshold_type set CV_THRESH_TRUNC调用它,则它将仅截断指定阈值以上的所有强度。低于阈值的强度将保持不变。也许

嘿,伙计们,我正在使用opencv做一些车辆识别工作,当我使用cvThershold将灰色图像转换为二值图像时,返回图像非常奇怪,二值图像假设只有两个值,0和255,但是,它包含其他值,如2,3254253,有人知道这是怎么发生的,而且cvCmps也有这个问题。

cvThreshold有各种超出正常二进制阈值的行为。它们在本节中进行了描述

例如,如果使用标志threshold_type set CV_THRESH_TRUNC调用它,则它将仅截断指定阈值以上的所有强度。低于阈值的强度将保持不变。也许这就是你奇怪结果的原因

如果您发布图像和代码(调用cvThreshold的位就足够了),我可能会提供更多帮助。

尝试以下方法:

/*
 * compile with:
 *
 * g++ -Wall -ggdb -I. -I/usr/include/opencv -L /usr/lib -lm -lcv -lhighgui -lcvaux threshold.cpp -o threshold.out
 */

#include <cv.h>    
#include <highgui.h>
#include <stdio.h>
#include <assert.h>

IplImage *
threshold(IplImage const *in, int threshold)
{
    assert(in->nChannels == 1);
    CvSize size = cvSize(in->width, in->height);
    IplImage *out = cvCreateImage(size, IPL_DEPTH_8U, 1);
    cvThreshold(in, out, threshold, 255, CV_THRESH_BINARY);

    return out;
}

void
show_image(char const *title, IplImage const *image)
{
    cvNamedWindow(title, CV_WINDOW_AUTOSIZE);
    cvShowImage(title, image);
    cvWaitKey(0);    
    cvDestroyWindow(title);
}

int
main(int argc, char **argv)
{
    if (argc < 2)
    {
        fprintf(stderr, "usage: %s in.png\n", argv[0]);
        return 1;
    }

    IplImage *in = cvLoadImage(argv[1]);
    IplImage *grey = in;

    if (in->nChannels != 1)
    {
        /*
         * For some reason, cvCreateImage returns an image with 3 channels even
         * when a greyscale image is specified (e.g. PGM).  Hack around this by
         * just taking the first channel of the image.  OpenCV uses BGR order,
         * so it will be the B channel.
         */
        CvSize size = cvSize(in->width, in->height);
        grey = cvCreateImage(size, IPL_DEPTH_8U, 1);
        cvSplit(in, grey, NULL, NULL, NULL);
        cvReleaseImage(&in);
    }

    IplImage *thres = threshold(grey, 127);
    show_image("thresholded", thres);
    cvReleaseImage(&thres);

    cvReleaseImage(&grey);
    return 0;
}
/*
*编译时使用:
*
*g++-Wall-ggdb-I.-I/usr/include/opencv-L/usr/lib-lm-lcv-lhighgui-lcvaux threshold.cpp-o threshold.out
*/
#包括
#包括
#包括

#包括SixShooter

谢谢,米莎,这是我的代码,CvThreashold(秒,dst,阈值,255,CV_阈值二进制)阈值的值是多少?您是如何加载src和dst映像的?有多少个通道,什么数据类型,等等?最后,您是否尝试过一个简单的应用程序,只加载灰度图像,设置阈值并将其保存到单独的文件中?