zoukankan      html  css  js  c++  java
  • 002: Opencv 4.0代码执行

    1. int main(int argc,char* argv[])详解

         argc记录了用户在运行程序的命令行中输入的参数的个数。  

         arg[]指向的数组中至少有一个字符指针,即arg[0].他通常指向程序中的可执行文件的文件名。在有些版本的编译器中还包括程序

    文件所在的路径。
        
    #include <iostream>
    #include <string>
    #include <sstream>
    using namespace std;
    
    // OpenCV includes
    #include "opencv2/core.hpp"
    #include "opencv2/highgui.hpp"
    using namespace cv;
    
    int main( int argc, const char** argv )
    {
       
    //
    argv[1]第一个参数是图像名
        Mat color = imread(argv[1]);
        Mat gray = imread(argv[1], IMREAD_GRAYSCALE); ///以灰度图的形式读取图像
    ///判断图像是否为空
    if(! color.data ) // Check for invalid input { cout << "Could not open or find the image" << std::endl ; return -1; } // Write images 将读取的灰度图像写入本地 imwrite("lenaGray.jpg", gray); // Get same pixel with opencv function int myRow=color.cols-1; int myCol=color.rows-1;
    ///通过color.at 获取三通道的图像对应的像素点的灰度值 auto pixel
    = color.at<Vec3b>(myRow, myCol); cout << "Pixel value (B,G,R): (" << (int)pixel[0] << "," << (int)pixel[1] << "," << (int)pixel[2] << ")" << endl; // show images // imshow("Lena BGR", color); imshow("Lena Gray", gray); // wait for any key press waitKey(0); return 0; }
    2.如何在window 环境中执行该任务。
     (1)ctrl+r进入控制台窗口,输入cd  /d  + exe所在的路径,进入exe所在文件夹
       (2) 根据实际参数个数 输入 ***.exe+参数1+参数2  然后回车
      

     3.但是无法在vs2017直接查看debug,因此还是要vs2017中设置

      点击项目——右键属性——调试——命令行参数(lena.jpg)

      设置对应的项目路径为 .Debug ,这里是相对路径注意

      调试程序,可以进入断点啦

      

  • 相关阅读:
    Symfony之入门学习
    git之fatal: Could not read from remote repository
    Class path contains multiple SLF4J bindings.
    php获取网址
    系统吞吐量(TPS)、用户并发量、性能测试概念和公式
    php tools 破解
    jQuery 图片裁剪插件 Jcrop
    php 上传文件 $_FILES['']['type']的值
    This is a bug I believe, and it took me 2-3 days to figure it out. Please do the following to get it working,
    curl_setopt — 设置 cURL 传输选项
  • 原文地址:https://www.cnblogs.com/codeAndlearn/p/11519402.html
Copyright © 2011-2022 走看看