Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.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

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
C++ 如何在OpenCV中使用16位灰度?_C++_Opencv_Graphics - Fatal编程技术网

C++ 如何在OpenCV中使用16位灰度?

C++ 如何在OpenCV中使用16位灰度?,c++,opencv,graphics,C++,Opencv,Graphics,我找不到这些问题的答案: 我可以使用OpenCV显示16位灰度图片吗?我尝试了imshow(),但OpenCV创建的窗口上没有显示任何内容 如何将16位灰度图片转换为B5G6R5图片?为了存储此结构,我应该使用什么参数创建cv::Mat?我尝试了cv::cvtColor(m_-cvTmp,tmp,cv_-GRAY2BGR565),但该函数不断崩溃。答案没有说出来 PS:我要处理的图像已经在内存中了。1)你必须看看这个 您的代码如下所示: Mat imageGrey = imread("<i

我找不到这些问题的答案:

  • 我可以使用OpenCV显示16位灰度图片吗?我尝试了
    imshow()
    ,但OpenCV创建的窗口上没有显示任何内容

  • 如何将16位灰度图片转换为B5G6R5图片?为了存储此结构,我应该使用什么参数创建
    cv::Mat
    ?我尝试了
    cv::cvtColor(m_-cvTmp,tmp,cv_-GRAY2BGR565)
    ,但该函数不断崩溃。答案没有说出来

  • PS:我要处理的图像已经在内存中了。

    1)你必须看看这个

    您的代码如下所示:

    Mat imageGrey = imread("<image_name>", CV_LOAD_IMAGE_GRAYSCALE);
    
    Mat imageGrey=imread(“,CV\u LOAD\u IMAGE\u灰度);
    
    (二)

    Mat imageGrey=imread(“,CV\u LOAD\u IMAGE\u灰度);
    Mat成像仪;
    CVT颜色(ImageGray、imageBGR、CV_GRAY2BGR565);
    

    它能工作吗?

    根据imshow的文档,它会自动将16位灰度缩放到8位,以便在屏幕上显示。我用以下程序对此进行了测试:

    #include <iostream>
    
    #include "opencv2/core/core.hpp"
    #include "opencv2/imgproc/imgproc.hpp"
    #include "opencv2/highgui/highgui.hpp"
    
    using namespace std;
    
    int main(int argc, char *argv[]) {
        cv::Mat image;
        image = cv::imread("pic2.jpg");
    
        if (!image.data) {
            std::cout << "Image file not found\n";
            return 1;
        }
    
        cv::cvtColor(image, image, CV_BGR2GRAY);
        cv::Mat pic16bit;
        image.convertTo(pic16bit, CV_16U, 255); //convert to 16-bit by multiplying all values by 255
    
        // create image window named "asdfasdf"
        cv::namedWindow("asdfasdf");
        // show the image on window
        cv::imshow("asdfasdf", pic16bit);
        // wait for key
        cv::waitKey(0);
    
        return 0;
    }
    
    #包括
    #包括“opencv2/core/core.hpp”
    #包括“opencv2/imgproc/imgproc.hpp”
    #包括“opencv2/highgui/highgui.hpp”
    使用名称空间std;
    int main(int argc,char*argv[]){
    cv::Mat图像;
    image=cv::imread(“pic2.jpg”);
    如果(!image.data){
    
    std::别忘了提到我正在处理的图像已经在内存中(来自另一个库)。我创建了一个符合其内部表示形式的cv::Mat,然后将数据memcpy。请确保在
    imshow
    之后调用
    waitKey
    。忽略
    waitKey
    可能是什么也没有出现的原因之一。我确实使用了waitKey,窗口在那里,但为空。你可能不应该说“屏幕上没有显示任何内容”。这与“屏幕上出现空白窗口”不同。您的问题越详细,您就越有可能得到有用的答案。@SSteve谢谢,我接受您的建议。谢谢。下次我将分开我的问题。
    #include <iostream>
    
    #include "opencv2/core/core.hpp"
    #include "opencv2/imgproc/imgproc.hpp"
    #include "opencv2/highgui/highgui.hpp"
    
    using namespace std;
    
    int main(int argc, char *argv[]) {
        cv::Mat image;
        image = cv::imread("pic2.jpg");
    
        if (!image.data) {
            std::cout << "Image file not found\n";
            return 1;
        }
    
        cv::cvtColor(image, image, CV_BGR2GRAY);
        cv::Mat pic16bit;
        image.convertTo(pic16bit, CV_16U, 255); //convert to 16-bit by multiplying all values by 255
    
        // create image window named "asdfasdf"
        cv::namedWindow("asdfasdf");
        // show the image on window
        cv::imshow("asdfasdf", pic16bit);
        // wait for key
        cv::waitKey(0);
    
        return 0;
    }