Skip to content

Instantly share code, notes, and snippets.

View tilongzs's full-sized avatar

阿米奥 tilongzs

View GitHub Profile
@tilongzs
tilongzs / rotateData.cpp
Last active November 10, 2023 02:44
逆时针旋转数据
// 例如将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];
@tilongzs
tilongzs / resizeImage.cpp
Last active September 14, 2023 03:08
Qt中,假如QVector<ushort> testAreaData是一个100*150的数组构成的图像,将它放大并填充至为200* 230的数组图像并且保持原始缩放比
#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());
// 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通道
@tilongzs
tilongzs / ProjectSceneCapture2DToWorld.cpp
Last active May 25, 2024 07:06
(Unreal Engine)场景捕捉组件2D坐标与世界坐标的相互转换
#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));
@tilongzs
tilongzs / bit.c
Last active March 2, 2023 08:21
C语言的位运算
static int setbit(int value, int position)
{
return value | (1 << position);
}
static int clrbit(int value, int position)
{
return value & ~(1 << position);
}
BOOL IsBigEndian()
{
  union NUM
  {
    int a;
    char b;
  }num;
  num.a = 0x1234;
  if( num.b == 0x12 )
  {
@tilongzs
tilongzs / ScrollTabBarView.dart
Last active September 5, 2022 07:02
向上滑动时 导航栏能够滑出屏幕,当用户向下滑动时,导航栏能迅速回到屏幕
import 'package:flutter/material.dart';
/*
* 向上滑动时 导航栏能够滑出屏幕,当用户向下滑动时,导航栏能迅速回到屏幕
* 参考:https://book.flutterchina.club/chapter6/nestedscrollview.html#_6-12-3-sliverappbar
* */
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@tilongzs
tilongzs / DisableEnableConnections.cpp
Created August 15, 2022 09:34
启用/禁用网络适配器
#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);
#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)));