鐩爣
瀛︿範錛?銆佷嬌鐢?span style="color: #0000ff;">imread杞藉叆鍥懼儚銆?br /> 2銆佷嬌鐢?span style="color: #0000ff;">namedWindow鍒涘緩鍛藉悕OpenCV紿楀彛銆?br /> 3銆佷嬌鐢?span style="color: #0000ff;">imshow鍦∣penCV紿楀彛涓樉紺哄浘鍍忋?
婧愮爜錛?br /> 1 #include <opencv2/core/core.hpp>
2 #include <opencv2/highgui/highgui.hpp>
3 #include <iostream>
4
5 using namespace cv;
6 using namespace std;
7
8 int main(int argc, char ** argv)
9 {
10 if (2 != argc)
11 {
12 cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
13 return -1;
14 }
15
16 Mat image;
17 image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
18
19 if (!image.data) // Check for invalid input
20 {
21 cout << "Could not open or find the image" << std::endl;
22 return -1;
23 }
24
25 namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display
26 imshow("Display window", image); // Show our image inside it.
27
28 waitKey(0); // wait for a keystroke in the window
29 return 0;
30 }
璇存槑錛?br />鍦ㄤ嬌鐢∣penCV 2 鐨勫姛鑳戒箣鍓嶏紝鍑犱箮鎬繪槸瑕佸寘鍚?
1銆?span style="color: #0000ff;">core 閮ㄥ垎錛屽畾涔夊簱鐨勫熀鏈瀯寤哄潡
2銆?span style="color: #0000ff;">highgui妯″潡錛屽寘鍚緭鍏ヨ緭鍑烘搷浣滃嚱鏁般?br />
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
榪橀渶瑕乮nclude<iostream>榪欐牱鏇村鏄撳湪console涓婅緭鍑鴻緭鍏ャ備負浜嗛伩鍏嶆暟鎹粨鏋勫拰鍑芥暟鍚嶇О涓庡叾浠栧簱鍐茬獊錛孫penCV鏈夎嚜宸辯殑鍛藉悕絀洪棿cv銆傚綋鐒朵負浜嗛伩鍏嶅湪姣忎釜鍏抽敭瀛楀墠閮藉姞cv::keyword錛屽彲浠ュ湪澶撮儴瀵煎叆璇ュ懡鍚嶇┖闂淬?br />using namespace cv;
using namespace std;
闇瑕佸湪鍛戒護琛岃緭鍏ユ湁鏁堢殑鍥懼儚鍚嶇О銆?br />if (2 != argc)
{
cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
鐒跺悗鍒涘緩Mat瀵硅薄鐢ㄤ簬瀛樺偍杞藉叆鐨勫浘鍍忔暟鎹?br />Mat image;
璋冪敤imread鍑芥暟杞藉叆鍥懼儚錛堝浘鍍忓悕縐頒負argv[1]鎸囧畾鐨勶級銆傜浜屼釜鍙傛暟鎸囧畾鍥懼儚鏍煎紡銆?br />1銆丆V_LOAD_IMAGE_UNCHANGED (<0) loads the image as is(including the alpha channel if present)
2銆丆V_LOAD_IMAGE_GRAYSCALE (0) loads the image as an intensity one
3銆丆V_LOAD_IMAGE_COLOR (>0) loads the image in the BGR format
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
濡傛灉絎簩涓弬鏁版湭鎸囧畾錛岄偅涔堥粯璁や負CV_LOAD_IMAGE_COLOR
涓轟簡媯鏌ュ浘鍍忔槸鍚︽甯歌澆鍏ワ紝鎴戜滑鐢?span style="color: #0000ff;">namedWindow鍑芥暟鍒涘緩涓涓狾penCV紿楀彛鏉ユ樉紺哄浘鍍忋傞渶瑕佹寚瀹氱獥鍙e悕縐板拰澶у皬銆?br />絎簩涓弬鏁伴粯璁や負錛歐INDOW_AUTOSIZE
1銆?span style="color: #0000ff;">WINDOW_AUTOSIZE 鍙敮鎸丵T騫沖彴銆?br />2銆?span style="color: #0000ff;">WINDOW_NORMAL QT涓婃敮鎸佺獥鍙h皟鏁村ぇ灝忋?br />
鏈鍚庡湪鍒涘緩鐨勭獥鍙d腑鏄劇ず鍥懼儚
imshow("Display window", image);
緇撴灉
緙栬瘧鎵ц紼嬪簭銆?br />./DisplayImage d:\apple.jpg

]]>