#pragma once #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include<iostream> #include<vector> using namespace std; using namespace cv; // Lớp chứa các blob class Blob { public: int xmax, xmin, ymax, ymin, xcenter, ycenter; vector<Point> region; int width, height; int size; bool isInBlob(Point a) { if (a.x >= xmin - 2 && a.x <= xmax + 2 && a.y >= ymin - 2 && a.y <= ymax + 2) return true; return false; } void Add(Point a) { region.push_back(a); xmax = max(a.x, xmax); xmin = min(a.x, xmin); ymin = min(a.y, ymin); ymax = max(a.y, ymax); xcenter = (xmax + xmin) / 2; ycenter = (ymax + ymin) / 2; size = (xmax - xmin) * (ymax - ymin); width = xmax - xmin; height = ymax - ymin; } Blob() { xmax = ymax = xcenter = ycenter = size = 0; width = height = 0; xmin = ymin = INT_MAX; } ~Blob() {} };
时间: 2023-06-17 18:04:21 浏览: 21
这段代码定义了一个名为 Blob 的类,用于存储图像中的 blob 区域的信息。Blob 类包含以下属性:
- xmax、xmin、ymax、ymin:blob 区域的最大/最小坐标值,用于计算 blob 区域的宽度和高度。
- xcenter、ycenter:blob 区域的中心点坐标。
- region:存储 blob 区域中的所有像素点坐标。
- width、height:blob 区域的宽度和高度。
- size:blob 区域的大小。
- Add(Point a):将一个像素点添加到 blob 区域中。
- isInBlob(Point a):判断一个像素点是否在 blob 区域中。
在实际使用中,可以使用该类来实现图像中的目标检测、分割等任务。
相关问题
我的头文件是这样写的#include <stdio.h> #include <math.h> #include <fstream> #include <iostream> #include <string>//getline #include <sstream> #include "stb_image.h" #pragma comment(lib, "openGL32.lib") #pragma comment(lib, "glu32.lib") #pragma comment(lib, "glaux.lib") #include <gl/glaux.h> #include "glew.h" #include "glut.h" #include <vector>,请问如何避免报错gl.h included before glew.h呢
在你的头文件中,应该将 `glew.h` 的引入放在 `gl.h` 的引入之前。因此,你应该将 `glew.h` 的引入语句移到 `gl.h` 的引入语句之前,就像这样:
```
#include <stdio.h>
#include <math.h>
#include <fstream>
#include <iostream>
#include <string>//getline
#include <sstream>
#include "stb_image.h"
#include <gl/glaux.h>
#include <vector>
#include "glew.h"
#include <gl/glut.h>
#pragma comment(lib, "openGL32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glaux.lib")
```
这样就能够避免 `gl.h included before glew.h` 的错误了。
/* Socket head file */ #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h>/*sockaddr_in{}*/ #include<arpa/inet.h> /* Unix standard head file */ #include<stdio.h> #include<stdlib.h> #include<string.h> #include<unistd.h> #include <errno.h>/* strerror(),perror(),errno head file*/ #include <sys/time.h> #include <sys/wait.h> #define MAXBUFF 1024 #define PORT 9999怎么改成windows系统
在Windows系统中,网络编程需要使用Winsock API,因此需要引入`<winsock2.h>`头文件。此外,需要在程序中调用`WSAStartup()`函数和`WSACleanup()`函数来初始化和释放Winsock库。
下面是在Windows系统下进行网络编程的头文件和常量定义示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib, "Ws2_32.lib")
#define MAXBUFF 1024
#define PORT 9999
```
其中,`<ws2tcpip.h>`头文件包含了一些网络编程相关的函数和结构体定义。`#pragma comment(lib, "Ws2_32.lib")`语句用于链接Winsock库。
需要注意的是,在Windows系统中,端口号的类型为`unsigned short`,而不是`int`。因此,定义端口号常量时应该使用`USHORT`类型:
```c
#define PORT (USHORT)9999
```
相关推荐















