bug修复 修复修复修复

好的,这里是更新后的代码,将所有 inRange 函数的第一个变量替换为 ZoomOutimage

cpp 复制代码
// 绿色分岔路
if (divergerColor == "green" && nextColor == "null")
{
    cv::Mat frameGreen, frameRed;
    frame2.copyTo(frameGreen); // 复制原始图像用于绿色二值化处理
    frame2.copyTo(frameRed);   // 复制原始图像用于红色二值化处理

    // 二值化绿色
    inRange(ZoomOutimage, colorgroup.greenMin, colorgroup.greenMax, frameGreen); // 二值化绿色
    int numberGreen = 0;
    for (int i = 0; i < frameGreen.rows; i++)
    {
        for (int j = 0; j < frameGreen.cols; j++)
        {
            if (frameGreen.at<uchar>(i, j) == 255)
            {
                numberGreen++;
            }
        }
    }

    // 二值化红色
    inRange(ZoomOutimage, colorgroup.redMin, colorgroup.redMax, frameRed); // 二值化红色
    int numberRed = 0;
    for (int i = 0; i < frameRed.rows; i++)
    {
        for (int j = 0; j < frameRed.cols; j++)
        {
            if (frameRed.at<uchar>(i, j) == 255)
            {
                numberRed++;
            }
        }
    }

    // 出现绿色条带
    if (numberGreen >= 500)
    {
        mythread.mode = divergeleft;
        cout << "recognize green divergeleft" << endl;
        divergerColor = "null";
        frame2 = frameGreen;
        return;
    }

    // 出现红色条带
    else if (numberRed >= 500)
    {
        mythread.mode = divergeleft;
        cout << "recognize red divergeleft" << endl;
        divergerColor = "null";
        frame2 = frameRed;
        return;
    }
}
// 红色分岔路
else if (divergerColor == "red" && nextColor == "null")
{
    cv::Mat frameGreen, frameRed;
    frame2.copyTo(frameGreen); // 复制原始图像用于绿色二值化处理
    frame2.copyTo(frameRed);   // 复制原始图像用于红色二值化处理

    // 二值化绿色
    inRange(ZoomOutimage, colorgroup.greenMin, colorgroup.greenMax, frameGreen); // 二值化绿色
    int numberGreen = 0;
    for (int i = 0; i < frameGreen.rows; i++)
    {
        for (int j = 0; j < frameGreen.cols; j++)
        {
            if (frameGreen.at<uchar>(i, j) == 255)
            {
                numberGreen++;
            }
        }
    }

    // 二值化红色
    inRange(ZoomOutimage, colorgroup.redMin, colorgroup.redMax, frameRed); // 二值化红色
    int numberRed = 0;
    for (int i = 0; i < frameRed.rows; i++)
    {
        for (int j = 0; j < frameRed.cols; j++)
        {
            if (frameRed.at<uchar>(i, j) == 255)
            {
                numberRed++;
            }
        }
    }

    // 出现绿色条带
    if (numberGreen >= 500)
    {
        mythread.mode = divergeright;
        cout << "recognize green divergeright" << endl;
        divergerColor = "null";
        frame2 = frameGreen;
        return;
    }

    // 出现红色条带
    else if (numberRed >= 500)
    {
        mythread.mode = divergeright;
        cout << "recognize red divergeright" << endl;
        divergerColor = "null";
        frame2 = frameRed;
        return;
    }
}

// 棕色住户识别
else if (residenceColor == "brown" && divergerColor == "null")
{
    // 复制原始图像用于二值化处理
    cv::Mat frameBrown, frameViolet;
    frame2.copyTo(frameBrown);
    frame2.copyTo(frameViolet);

    inRange(ZoomOutimage, colorgroup.brownMin, colorgroup.brownMax, frameBrown); // 二值化棕色
    int numberBrown = 0;
    for (int i = 0; i < frameBrown.rows; i++)
    {
        for (int j = 0; j < frameBrown.cols; j++)
        {
            if (frameBrown.at<uchar>(i, j) == 255)
            {
                numberBrown++;
            }
        }
    }

    inRange(ZoomOutimage, colorgroup.violetMin, colorgroup.violetMax, frameViolet); // 二值化紫色
    int numberViolet = 0;
    for (int i = 0; i < frameViolet.rows; i++)
    {
        for (int j = 0; j < frameViolet.cols; j++)
        {
            if (frameViolet.at<uchar>(i, j) == 255)
            {
                numberViolet++;
            }
        }
    }

    // 出现红色或棕色条带
    if (numberBrown >= 500)
    {
        mythread.mode = residenceright;
        cout << "recognize brown" << endl;
        residenceColor = "null";
        frame2 = frameBrown;
        return;
    }
    else if (numberViolet >= 500)
    {
        mythread.mode = residenceright;
        cout << "recognize Violet" << endl;
        residenceColor = "null";
        frame2 = frameViolet;
        return;
    }
}
// 紫色住户识别
else if (residenceColor == "violet" && divergerColor == "null")
{
    // 复制原始图像用于二值化处理
    cv::Mat frameBrown, frameViolet;
    frame2.copyTo(frameBrown);
    frame2.copyTo(frameViolet);

    inRange(ZoomOutimage, colorgroup.brownMin, colorgroup.brownMax, frameBrown); // 二值化棕色
    int numberBrown = 0;
    for (int i = 0; i < frameBrown.rows; i++)
    {
        for (int j = 0; j < frameBrown.cols; j++)
        {
            if (frameBrown.at<uchar>(i, j) == 255)
            {
                numberBrown++;
            }
        }
    }

    inRange(ZoomOutimage, colorgroup.violetMin, colorgroup.violetMax, frameViolet); // 二值化紫色
    int numberViolet = 0;
    for (int i = 0; i < frameViolet.rows; i++)
    {
        for (int j = 0; j < frameViolet.cols; j++)
        {
            if (frameViolet.at<uchar>(i, j) == 255)
            {
                numberViolet++;
            }
        }
    }
    // 出现红色或棕色条带
    if (numberBrown >= 500)
    {
        mythread.mode = residenceleft;
        cout << "recognize brown" << endl;
        residenceColor = "null";
        frame2 = frameBrown;
        return;
    }
    else if (numberViolet >= 500)
    {
        mythread.mode = residenceleft;
        cout << "recognize Violet" << endl;
        residenceColor = "null";
        frame2 = frameViolet;
        return;
    }
}

在上述代码中,所有 inRange 函数的第一个参数都已经替换为 ZoomOutimage。这样确保了所有二值化处理都是在 ZoomOutimage 上进行的。

相关推荐
向上的车轮3 小时前
软件世界中的超级bug有哪些?
bug
测试小小怪下士2 天前
Bug的严重等级和优先级别与分类
bug
测试小小怪下士2 天前
软件Bug和缺陷的区别是什么?
bug
Matrix704 天前
Spark_写ORALCE:ORA-01426 numeric overflow 问题解决
bug
明耀6 天前
WPF Gif图谱 如果隐藏的话会存在BUG
c#·bug·wpf
|Ringleader|6 天前
【Unity Bug 随记】unity version control 报 xx is not in a workspace.
unity·bug·版本管理·uvc
a1111111111ss7 天前
猫狗识别之BUG汇总
bug
晓同哇哇~7 天前
Wxml2Canvas小程序将dom转为图片,bug总结
bug·canva可画
小波波啊7 天前
idea远程debug调试
ide·bug·intellij-idea
冷小鱼7 天前
【BUG】Error: llama runner process has terminated: exit status 127
bug·llama·ollama