opencv单个窗口中显示多个图像

本文介绍如何利用OpenCV库在一个主窗口中创建多个子窗口,并在每个子窗口中展示不同的图像。通过调用特定的函数showManyImages,可以实现在一个单一的界面下同时查看多幅图像,这对于图像处理和分析任务非常有用。
摘要由CSDN通过智能技术生成

在一个窗口显示多个图像子窗口。函数showManyImages。

#include <stdio.h>
#include <stdarg.h>
#include <time.h>



// 单窗口显示多幅图像的函数
void showMultiImages(char* title, int nArgs, ...) 
{

	Mat DispImage;
	int size;    
	int ind;      
	int x, y;    
	int w, h;    
	int r, c;

	float scale;

	int max;

	int space;

	if(nArgs <= 0) {
		printf("Number of arguments too small..../n");
		return;
	}
	else if(nArgs > 12) {
		printf("Number of arguments too large..../n");
		return;
	}
	else if (nArgs == 1) {
		r = c = 1;
		size = 300;
	}
	else if (nArgs == 2) {
		r = 2; c = 1;
		size = 300;
	}
	else if (nArgs == 3 || nArgs == 4) {
		r = 2; c = 2;
		size = 300;
	}
	else if (nArgs =
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的示例代码,可以在 Xcode 上使用 OpenCV 和 DCMTK 库读取 DICOM 图像文件,并允许用户使用鼠标拖动来画圆并将其显示图像上: ```cpp #include <iostream> #include <vector> #include <opencv2/opencv.hpp> #include <dcmtk/dcmdata/dctk.h> using namespace std; using namespace cv; // 回调函数,用于鼠标事件处理 void on_mouse(int event, int x, int y, int flags, void* param); int main(int argc, char** argv) { // 读取 DICOM 文件 DcmFileFormat fileformat; OFCondition status = fileformat.loadFile(argv[1]); if (status.bad()) { cerr << "Error: cannot read DICOM file" << endl; return -1; } // 提取图像像素数据和相关信息 DcmDataset* dataset = fileformat.getDataset(); Uint16 rows, cols; dataset->findAndGetUint16(DCM_Rows, rows); dataset->findAndGetUint16(DCM_Columns, cols); Uint16* pixel_data; dataset->findAndGetUint16Array(DCM_PixelData, pixel_data); // 将像素数据转换为 OpenCV Mat 对象 Mat image(rows, cols, CV_16UC1, pixel_data); // 创建窗口显示图像 namedWindow("DICOM Image", WINDOW_NORMAL); imshow("DICOM Image", image); // 设置鼠标事件回调函数 setMouseCallback("DICOM Image", on_mouse, &image); // 等待用户按下任意键 waitKey(0); return 0; } void on_mouse(int event, int x, int y, int flags, void* param) { // 如果用户按下左键并拖动鼠标,则画圆并显示图像上 if (event == EVENT_LBUTTONDOWN && (flags & EVENT_FLAG_LBUTTON)) { Mat& image = *(Mat*)param; circle(image, Point(x, y), 20, Scalar(65535), 2); imshow("DICOM Image", image); } } ``` 该代码打开一个 DICOM 文件,显示图像,并允许用户使用鼠标拖动来画圆并将其显示图像上。请注意,该代码仅绘制了单个圆形,如果需要绘制多个圆形,则需要将其存储在一个容器,并在 `on_mouse` 函数迭代它们并画出它们。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值