This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 例如将200*100的图像数据逆时针旋转90°为100*200的图像数据 | |
auto CounterClockwiseRotationData90 = [](ushort* data, int colCount, int rowCount, ushort* rotateData) | |
{ | |
// 逆时针旋转90度 | |
// 如果原数组中的元素在(row, col)位置,那么在新数组中,该元素应该在(rowCount - 1 - col, row)位置 | |
for (int row = 0; row < rowCount; ++row) | |
{ | |
for (int col = 0; col < colCount; ++col) | |
{ | |
rotateData[(colCount - 1 - col) * rowCount + row] = data[row * colCount + col]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <opencv2/opencv.hpp> | |
/* | |
这个函数首先将QVector<ushort>转换为cv::Mat,然后计算缩放比例,并使用cv::resize函数进行缩放。然后,它创建一个新的输出矩阵,并将缩放后的图像复制到输出矩阵的中心。最后,它将结果转换回QVector<ushort>。 | |
*/ | |
void resizeImage(QVector<ushort>& input, QVector<ushort>& output, int inputWidth, int inputHeight, int outputWidth, int outputHeight, bool isKeepAspectRatio) | |
{ | |
// 将输入转换为OpenCV矩阵 | |
cv::Mat inputMat(inputHeight, inputWidth, CV_16U, input.data()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// QImage 转 Mat | |
// Qt读入彩色图后一般为Format_RGB32格式(4通道),而OpenCV一般用3通道的,因此进行了转换。 | |
cv::Mat QImage2Mat(const QImage& image) | |
{ | |
cv::Mat mat; | |
switch (image.format()) | |
{ | |
case QImage::Format_RGB32: //一般Qt读入彩色图后为此格式 | |
mat = cv::Mat(image.height(), image.width(), CV_8UC4, (void*)image.constBits(), image.bytesPerLine()); | |
cv::cvtColor(mat,mat,cv::COLOR_BGRA2BGR); //转3通道 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Components/SceneCaptureComponent2D.h" | |
#include "Engine/TextureRenderTarget2D.h" | |
void ProjectSceneCaptureToWorld(const class USceneCaptureComponent2D* sceneCaptureCompone2D, const FVector2D& sceneCapturePosition, FVector& worldPosition, FVector& worldDirection) | |
{ | |
// 计算视口矩阵 | |
const FTransform& transform = sceneCaptureCompone2D->GetComponentToWorld(); | |
FMatrix viewMatrix = transform.ToInverseMatrixWithScale(); | |
viewMatrix = viewMatrix * FMatrix(FPlane(0, 0, 1, 0), FPlane(1, 0, 0, 0), FPlane(0, 1, 0, 0), FPlane(0, 0, 0, 1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int setbit(int value, int position) | |
{ | |
return value | (1 << position); | |
} | |
static int clrbit(int value, int position) | |
{ | |
return value & ~(1 << position); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOOL IsBigEndian() | |
{ | |
union NUM | |
{ | |
int a; | |
char b; | |
}num; | |
num.a = 0x1234; | |
if( num.b == 0x12 ) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
/* | |
* 向上滑动时 导航栏能够滑出屏幕,当用户向下滑动时,导航栏能迅速回到屏幕 | |
* 参考:https://book.flutterchina.club/chapter6/nestedscrollview.html#_6-12-3-sliverappbar | |
* */ | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatefulWidget { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <netcon.h> | |
// Enable/Disable Wireless connection programvatically | |
// https://forums.codeguru.com/showthread.php?404103-RESOLVED-Enable-Disable-Wireless-connection-programvatically | |
HRESULT DisableEnableConnections(BOOL bEnable) | |
{ | |
HRESULT hr = E_FAIL; | |
CoInitialize(NULL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
int main() | |
{ | |
int r = 20; | |
for (int z = 0; z <= 2 * r; z += 2) { | |
int x = (int)round(r - sqrt(r * r - (r - z) * (r - z))); |