V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
BlueSchwarz
V2EX  ›  问与答

求教 OpenCV 描绘轮廓的问题

  •  
  •   BlueSchwarz · Apr 11, 2019 · 2119 views
    This topic created in 2579 days ago, the information mentioned may be changed or developed.

    用 OpenCV 做一个检测图形的程序,现在已经可以检测到轮廓了,但在原图画轮廓的时候,轮廓总是黑色的,我明明用的是红色的呀?有没有大佬来看看,是哪里有问题。

    Mat image = src.clone();
    drawContours(image, contours, t, Scalar(0, 0, 255), 2, LINE_8, Mat(), 0, Point());
    
    7 replies    2019-04-11 09:34:07 +08:00
    epleone
        1
    epleone  
       Apr 11, 2019
    原图是单通道的会有这种情况
    BlueSchwarz
        2
    BlueSchwarz  
    OP
       Apr 11, 2019
    @epleone 原图我用的是 24 位深的 jpg,应该支持彩色的吧?单通道是什么,不清楚。
    BlueSchwarz
        3
    BlueSchwarz  
    OP
       Apr 11, 2019
    @epleone Mat src = imread("sample_2.png");
    epleone
        4
    epleone  
       Apr 11, 2019
    你可以打印下要显示图片的通道数 image.channels()
    如果等于 1,使用 cvtColor(image, image, CV_GRAY2BGR)转换下就行了
    BlueSchwarz
        5
    BlueSchwarz  
    OP
       Apr 11, 2019
    @epleone 找到原因了,image 之前被我拷贝给 image_Gray 的时候忘记用 clone()了,然后 image_Gray 更改了 image 的数据
    VShawn
        6
    VShawn  
       Apr 11, 2019
    用 imagewatch 单步调试很容易发现这种问题
    BlueSchwarz
        7
    BlueSchwarz  
    OP
       Apr 11, 2019
    @VShawn 我待会儿安装一下这个插件试试看,多谢了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2347 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 05:49 · PVG 13:49 · LAX 22:49 · JFK 01:49
    ♥ Do have faith in what you're doing.