Zaris naslovnic iz zaznave obrazov (OpenCV) namesto LLM ugibanja — glave se ne rezejo vec
This commit is contained in:
@@ -7,6 +7,23 @@ const openai = new OpenAI({
|
||||
baseURL: process.env.AI_INTEGRATIONS_OPENAI_BASE_URL,
|
||||
});
|
||||
|
||||
|
||||
// Zaris iz zaznave obrazov (OpenCV) — /opt/folxtv-uploads/focal_points.json,
|
||||
// ki ga polni /opt/folx-fix/focal_calc.py na openclaw1. LLM je zaris ugibal in
|
||||
// je pri portretnih slikah rezal glave, zato ima ta datoteka prednost.
|
||||
const DETECTED_PATH = path.join(process.cwd(), "client/public/uploads/focal_points.json");
|
||||
let detected: Record<string, { x: number; y: number }> = {};
|
||||
let detectedMtime = 0;
|
||||
function loadDetected() {
|
||||
try {
|
||||
const st = fs.statSync(DETECTED_PATH);
|
||||
if (st.mtimeMs === detectedMtime) return;
|
||||
detected = JSON.parse(fs.readFileSync(DETECTED_PATH, "utf-8"));
|
||||
detectedMtime = st.mtimeMs;
|
||||
console.log("[focal-point] zaznanih zarisov:", Object.keys(detected).length);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const cache = new Map<string, { x: number; y: number }>();
|
||||
|
||||
const manualOverrides: Record<string, { x: number; y: number }> = {
|
||||
@@ -33,6 +50,11 @@ export async function analyzeFocalPoint(imagePath: string): Promise<{ x: number;
|
||||
cache.set(originalPath, manualOverrides[originalPath]);
|
||||
return manualOverrides[originalPath];
|
||||
}
|
||||
loadDetected();
|
||||
if (detected[originalPath]) {
|
||||
cache.set(originalPath, detected[originalPath]);
|
||||
return detected[originalPath];
|
||||
}
|
||||
if (cache.has(originalPath)) {
|
||||
return cache.get(originalPath)!;
|
||||
}
|
||||
@@ -102,9 +124,14 @@ export async function analyzeAllArticleImages(articles: Array<{ coverImage: stri
|
||||
}
|
||||
|
||||
export function getCachedFocalPoints(): Record<string, { x: number; y: number }> {
|
||||
loadDetected();
|
||||
const result: Record<string, { x: number; y: number }> = {};
|
||||
for (const [key, value] of cache.entries()) {
|
||||
result[key] = value;
|
||||
}
|
||||
// zaznani zaris ima prednost pred LLM ugibanjem
|
||||
for (const [key, value] of Object.entries(detected)) {
|
||||
result[key] = value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user