import cv2
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
# ✅ دالة لتحليل الشموع اليابانية من الصورة
def process_candlestick_chart(image_path):
# تحميل الصورة
img = cv2.imread(image_path)
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# تحسين التباين وإزالة الضوضاء
blurred = cv2.GaussianBlur(img_gray, (5, 5), 0)
edges = cv2.Canny(blurred, 50, 150)
# العثور على المستطيلات (الشموع اليابانية)
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
candlesticks = []
for cnt in contours:
x, y, w, h = cv2.boundingRect(cnt)
if h > 10 and w > 3: # شرط لتحديد الشموع فقط
candlesticks.append((x, y, w, h))
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
# عرض الصورة مع الشموع المحددة
plt.figure(figsize=(10, 5))
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title(f"تم اكتشاف {len(candlesticks)} شموع")
plt.show()
return candlesticks
# ✅ دالة لاستخراج ميزات الشموع للتدريب
def extract_features(candlesticks):
features = []
for (x, y, w, h) in candlesticks:
ratio = h / w # نسبة الارتفاع إلى العرض
features.append([w, h, ratio]) # إضافة الخصائص
return np.array(features)
# ✅ إنشاء نموذج ذكاء اصطناعي بسيط لتصنيف الشموع
def create_model():
model = Sequential([
Dense(32, activation='relu', input_shape=(3,)),
Dense(16, activation='relu'),
Dense(3, activation='softmax') # 3 أنواع من الشموع: صعودي، هبوطي، محايد
])
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
return model
# ✅ تحميل وتحليل الصورة
image_path = "candlestick_chart.jpg" # ضع اسم ملف الصورة هنا
candlesticks = process_candlestick_chart(image_path)
# ✅ استخراج الميزات من الشموع المكتشفة
features = extract_features(candlesticks)
print("📊 ميزات الشموع:", features[:5]) # طباعة أول 5 شموع
# ✅ تدريب نموذج الذكاء الاصطناعي (اختبار فقط)
model = create_model()
X_train = np.random.rand(100, 3) # بيانات عشوائية كاختبار
y_train = np.random.randint(0, 3, (100, 3)) # تصنيفات عشوائية
# تدريب النموذج
model.fit(X_train, y_train, epochs=10)
print("✅ النموذج جاهز لتصنيف الشموع!")
لم يتم العثور على أي نتائج