Created
April 15, 2025 16:55
-
-
Save zr0n/f43b74eb6c2f189aeac1408352de439c to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
#include <vector> | |
#include <random> | |
using namespace cv; | |
using namespace std; | |
// Função para calcular o campo de velocidade (exemplo: vórtice) | |
Point2f calculateVelocity(Point2f pos, Size imgSize) { | |
// Centralizar coordenadas | |
Point2f center(imgSize.width/2.0f, imgSize.height/2.0f); | |
Point2f relPos = pos - center; | |
// Criar um campo de velocidade vorticional | |
float radius = norm(relPos); | |
if (radius < 5.0f) radius = 5.0f; // Evitar divisão por zero | |
// Velocidade tangencial (vórtice) | |
float tangentSpeed = 100.0f / radius; | |
// Retornar vetor velocidade | |
return Point2f(-relPos.y * tangentSpeed / radius, | |
relPos.x * tangentSpeed / radius); | |
} | |
// Função para desenhar linhas de corrente | |
void drawStreamlines(Mat& output, Size imgSize, int numLines, int steps) { | |
RNG rng(getTickCount()); // Gerador de números aleatórios | |
for (int i = 0; i < numLines; ++i) { | |
// Posição inicial aleatória | |
Point2f pt(rng.uniform(0, imgSize.width), | |
rng.uniform(0, imgSize.height)); | |
vector<Point> points; // Armazenar pontos da linha | |
for (int j = 0; j < steps; ++j) { | |
points.push_back(Point(pt)); | |
// Calcular velocidade na posição atual | |
Point2f velocity = calculateVelocity(pt, imgSize); | |
// Normalizar e escalar o passo | |
float velNorm = norm(velocity); | |
if (velNorm > 0) { | |
velocity *= 5.0f / velNorm; // Tamanho do passo constante | |
} | |
// Atualizar posição | |
pt += velocity; | |
// Verificar se está dentro da imagem | |
if (pt.x < 0 || pt.y < 0 || pt.x >= imgSize.width || pt.y >= imgSize.height) { | |
break; | |
} | |
} | |
// Desenhar a linha de corrente | |
for (size_t j = 1; j < points.size(); ++j) { | |
// Cor varia com a posição (opcional) | |
Scalar color(200 * points[j].y / imgSize.height, | |
100, | |
200 * points[j].x / imgSize.width); | |
// Espessura pode variar com a velocidade | |
int thickness = 1 + (j % 3); | |
line(output, points[j-1], points[j], color, thickness); | |
} | |
} | |
} | |
int main(int argc, char** argv) { | |
// Carregar imagem de entrada | |
Mat inputImage; | |
if (argc > 1) { | |
inputImage = imread(argv[1]); | |
} else { | |
// Se nenhuma imagem for fornecida, criar uma imagem preta | |
input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment