float[imgW * imgH * 3] 数据转换成std::vector<cv::Vec3f>
时间: 2024-01-20 08:02:53 浏览: 113
可以使用以下代码将float[imgW * imgH * 3]数据转换成std::vector<cv::Vec3f>:
```c++
// imgData为float[imgW * imgH * 3]数据,imgW为图像宽度,imgH为图像高度
std::vector<cv::Vec3f> imgVec;
imgVec.reserve(imgW * imgH);
for (int i = 0; i < imgW * imgH; ++i) {
float b = imgData[i * 3];
float g = imgData[i * 3 + 1];
float r = imgData[i * 3 + 2];
imgVec.emplace_back(b, g, r);
}
```
这里利用了cv::Vec3f类型的构造函数,将每个像素点的BGR三个通道值转换成Vec3f类型,最后将其加入到std::vector<cv::Vec3f>中。注意,这里需要使用reserve()方法提前分配好vector的内存,以避免不必要的内存分配和拷贝。
相关问题
FormInfo class FormInfo <<partial>> [ +Formlnfo0- button1 Click(sender:obiect, e:EventArgs) : void+ SetText(run:double, walk:double) : void Form <-- FormInfo Common class Common!+ static) map left lon : double +{static) map top lat : double +{static map right lon : double +{static' map bottom lat : double class Station { +longitute :double <<get>> <<set> >+latitude :double <<get> > <<set>> + staionname :string <<get>> <<set>> + stationlD :int <<get> > <<set>> + address :string <<get>> <<set> > + totalDocks :int <<get> > <<set> > + docksln :int <<get> > < <set> > + status : string <<get> > < <set> > Station-->"screenPoint"Point Form1 class Form1 <<partial>> !-imgH:int- imgW :int isStartSite : bool isEndSite : boolI startIndex :int- endIndex :int - isPlanRoute : bool = false- m distance : double = 0 +Form10 Form1 Shown(sender:obiect,e:EventArgs) : void panelRight SizeChanged(sender:obiect,e:EventArgs): void panelButtom SizeChanged(sender:object, e:EventArgs) : voidForm1 Paint(sender:object, e:PaintEventArgs) : void buttonlmport Click(sender:object, e:EventArgs) : void Import(fileName:string): void GPSToScreen(lon:double.lat:double): PointGetTitude(point:Point): doubel listStations SelectedlndexChanged(sender:obiect, e:EventArgs) : void panel2 Paint(sender:object, e:PaintEventArgs) : voidcheckAll Click(sender:obiect, e:EventArgs) : void comboBox1 SelectedndexChanged(sender:obiect.e:EventAras): voioDrawReqularPoly(x:float, y:float, radius:double, sideCount:int) : PointF panelMouse Paint(sender:obiect,e:PaintEventArgs) : void panelMouse MouseMove(sender:object, e:MouseEventArgs) : voidpanelMouse MouseClick(sender:object, e:MouseEventArgs) : voidbutton1 Click(sender:object, e:EventArgs) : void setRoute0:void - setWalkRoute() : void - comboBox1 TextChanged(sender:object, e:EventArgs) : void class"List1"<T>{ MapHelper class MapHelper!<<const>> EarthRadius : double = 6378.137Istatic' Rad(d:double) : double +Istatic' GetDistance(firstLatitude:double.firstLongitude:double, secondLatitude:doublesecondLongitude:double): double+Istatic1 GetPointDistance(firstPoint:string,secondPoint:string): double Form <-- Form1 Form1-->"allstation<Station>""List1"Form1-->"startPoint"Point Form1-->"endPoint"Point Form1-->"startList<PointFI>""List1" "routeList<PointFIl>""List1Form1-->Form1-->"endList<PointFIl>""List1"Form1-->"m formlnfo"FormInfo画类图
根据提供的信息,可以绘制以下类图:
```
+-----------------------------------+
| FormInfo |
+-----------------------------------+
| +Formlnfo0- button1 Click(...) |
| +SetText(run:double, walk:double) |
+-----------------------------------+
+-----------------------------+
| Form |
+-----------------------------+
| <-- FormInfo |
+-----------------------------+
+-----------------------------+
| Common |
+-----------------------------+
| +{static} map left lon |
| +{static} map top lat |
| +{static} map right lon |
| +{static} map bottom lat |
+-----------------------------+
+-----------------------------+
| Station |
+-----------------------------+
| +longitude : double |
| +latitude : double |
| +stationname : string |
| +stationlD : int |
| +address : string |
| +totalDocks : int |
| +docksln : int |
| +status : string |
| --> "screenPoint" Point |
+-----------------------------+
+-----------------------------+
| Form1 |
+-----------------------------+
| <-- FormInfo |
| - imgH: int |
| - imgW: int |
| - isStartSite: bool |
| - isEndSite: bool |
| - startIndex: int |
| - endIndex: int |
| - isPlanRoute: bool = false |
| - m distance: double = 0 |
| +Form10 |
| +Form1 Shown(...) |
| +panelRight SizeChanged(...)|
| +panelButtom SizeChanged(...)|
| +Form1 Paint(...) |
| +buttonlmport Click(...) |
| +Import(fileName:string) |
| +GPSToScreen(lon:double, lat:double): Point |
| +GetTitude(point:Point): double |
| +listStations SelectedlndexChanged(...) |
| +panel2 Paint(...) |
| +checkAll Click(...) |
| +comboBox1 SelectedndexChanged(...) |
| +DrawReqularPoly(...) |
| +panelMouse Paint(...) |
| +panelMouse MouseMove(...) |
| +panelMouse MouseClick(...) |
| +button1 Click(...) |
| - setRoute0:void |
| - setWalkRoute() : void |
| - comboBox1 TextChanged(...)|
+-----------------------------+
+-----------------------------+
| List1<T> |
+-----------------------------+
+-----------------------------+
| MapHelper |
+-----------------------------+
| <<const>> EarthRadius: double = 6378.137 |
| +static Rad(d: double): double |
| +static GetDistance(firstLatitude: double, firstLongitude: double, secondLatitude: double, secondLongitude: double): double |
| +static GetPointDistance(firstPoint: string, secondPoint: string): double |
+-----------------------------+
```
请注意,这只是根据提供的信息绘制的大致类图,可能会有一些缺失或错误。
new float[imgW * imgH * 8]在函数参数里要怎么表达
在函数参数中,可以这样表达:
```
void function_name(float* img_data, int imgW, int imgH) {
// Function code
}
// 调用函数时,可以这样传递参数
int imgW = 100;
int imgH = 200;
float* img_data = new float[imgW * imgH * 8];
function_name(img_data, imgW, imgH);
```
其中,`float* img_data` 表示指向 `float` 类型数据的指针,`int imgW` 和 `int imgH` 表示图片的宽和高。在调用函数时,需要先创建一个大小为 `imgW * imgH * 8` 的 `float` 类型数组,然后将其指针传递给函数。
阅读全文