久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

是否有公式可以確定給定 BGR 值的整體顏色?(Ope

Is there a formula to determine overall color given BGR values? (OpenCV and C++)(是否有公式可以確定給定 BGR 值的整體顏色?(OpenCV 和 C++))
本文介紹了是否有公式可以確定給定 BGR 值的整體顏色?(OpenCV 和 C++)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 C++ 和 OpenCV 制作一個函數,該函數將檢測圖像中像素的顏色,確定它所在的顏色范圍,并將其替換為通用顏色.例如,綠色的范圍可以從深綠色到淺綠色,程序會確定它仍然是綠色并用簡單的綠色替換它,從而使輸出圖像看起來非常簡單.一切都已設置,但我無法定義每個范圍的特征,并且很好奇是否有人知道或公式可以根據 BGR 值確定像素的整體顏色.如果沒有,我將不得不做很多實驗并自己制作,但如果已經存在可以節省時間的東西.我已經做了很多研究,但到目前為止還沒有發現任何東西.

I am making a function using C++ and OpenCV that will detect the color of a pixel in an image, determine what color range it is in, and replace it with a generic color. For example, green could range from dark green to light green, the program would determine that its still green and replace it with a simple green, making the output image very simple looking. everything is set up but I'm having trouble defining the characteristics of each range and was curious if anyone knows or a formula that, given BGR values, could determine the overall color of a pixel. If not I'll have to do much experimentation and make it myself, but if something already exists that'd save time. I've done plenty of research and haven't found anything so far.

推薦答案

如果你想讓你的圖像更簡單(即顏色更少),但好看,你有幾個選擇:

If you want to make your image simpler (i.e. with less colors), but good looking, you have a few options:

  • 一個簡單的方法是將圖像除以(整數除法)一個因子 N,然后乘以一個因子 N.

  • A simple approach would be to divide (integer division) by a factor N the image, and then multiply by a factor N.

或者您可以使用一些聚類算法(例如此處顯示的 kmeans 或中值切割算法)將圖像劃分為 K 種顏色.

Or you can divide your image into K colors, using some clustering algorithm such as kmeans showed here, or median-cut algorithm.

原圖:

減少顏色(量化,N = 64):

減少顏色(聚集,K = 8):

代碼量化:

#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;

int main()
{
    Mat3b img = imread("path_to_image");

    imshow("Original", img);

    uchar N = 64;
    img  /= N;
    img  *= N;

    imshow("Reduced", img);
    waitKey();

    return 0;
}

代碼kmeans:

#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;

int main()
{
    Mat3b img = imread("path_to_image");

    imshow("Original", img);

    // Cluster

    int K = 8;
    int n = img.rows * img.cols;
    Mat data = img.reshape(1, n);
    data.convertTo(data, CV_32F);

    vector<int> labels;
    Mat1f colors;
    kmeans(data, K, labels, cv::TermCriteria(), 1, cv::KMEANS_PP_CENTERS, colors);

    for (int i = 0; i < n; ++i)
    {
        data.at<float>(i, 0) = colors(labels[i], 0);
        data.at<float>(i, 1) = colors(labels[i], 1);
        data.at<float>(i, 2) = colors(labels[i], 2);
    }

    Mat reduced = data.reshape(3, img.rows);
    reduced.convertTo(reduced, CV_8U);


    imshow("Reduced", reduced);
    waitKey();

    return 0;
}

這篇關于是否有公式可以確定給定 BGR 值的整體顏色?(OpenCV 和 C++)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉圖像而不使用 OpenCV 函數)
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
OpenCV unable to set up SVM Parameters(OpenCV 無法設置 SVM 參數)
Convert a single color with cvtColor(使用 cvtColor 轉換單一顏色)
主站蜘蛛池模板: www免费视频 | 视频1区2区 | 全免费a级毛片免费看视频免 | 91成人精品| 尤物视频在线免费观看 | 国产精品久久久久久久7电影 | 国产精品久久久久久久久久尿 | wwwww在线观看 | 欧美精品福利 | 影音先锋中文在线 | 成人做爰69片免费观看 | 日韩在线中文字幕 | 中文字幕免费在线 | 亚洲国产中文字幕 | 欧美日韩视频 | 亚洲成av人片在线观看无码 | 精品成人一区二区 | 一区二区三区四区免费在线观看 | 日韩最新网站 | 亚洲欧美日本在线 | 日韩在线视频免费观看 | av手机免费在线观看 | 国产一区视频在线 | 国产一区 | 激情黄色在线观看 | 巨大荫蒂视频欧美另类大 | 成人一区二区三区 | 成人免费看电影 | 久久久久久久国产精品影院 | 日韩视频一区二区三区 | 日韩精品一区二区三区在线观看 | 99这里只有精品视频 | 美美女高清毛片视频免费观看 | 喷水毛片 | 午夜小电影 | 日韩精品在线免费 | 精品国产欧美 | 99久久久无码国产精品 | 亚洲精品一区二三区不卡 | av在线视 | 亚洲精品国产一区 |