اذهب إلى المحتوى
  • 0

دمج صورتين في بايثون

Omar Ashraf16

السؤال

Recommended Posts

  • 0

الأسئلة الإختبارية لا يتم الإجابة عليها بشكل مباشر، لكن كمساعدة في تنفيذ المطلوب.

المطلوب  دمج صورتين بواسطة بايثون، لذا ستحتاج استخدام مكتبة OpenCV لمعالجة الصور ومكتبة NumPy للتعامل مع المصفوفات.

حيث ستقوم بقراءة الصورة الأولى من خلال دالة معينة في OpenCV، ثم نفس الأمر للصورة الثانية.

بعد ذلك  التحقق من تطابق أبعاد الصورتين و إظهار رسالة خطأ إذا لم تتطابق أبعاد الصورتين، ثم دمج الصورتين باستخدام دالة معينة في OpenCV أيضًا.

بعد ذلك عرض الصورة الناتجة و انتظار ضغط مفتاح لإغلاق النافذة، ويمكن حفظ الصورة الناتجة في ملف باسم output.jpg لكن تلك نقطة إختيارية.

وتستطيع استخدام مكتبات أخرى لدمج الصور مثل Pillow.

رابط هذا التعليق
شارك على الشبكات الإجتماعية

  • 0

مرحبا

I am so curios to solve this problem,  you can achieve this task using the OpenCV library in Python  

import cv2

def add_images(image1_path, image2_path):
    # Read the images
    image1 = cv2.imread(image1_path)
    image2 = cv2.imread(image2_path)

    # Ensure both images have the same dimensions
    image2 = cv2.resize(image2, (image1.shape[1], image1.shape[0]))

    # Add the images
    result = cv2.addWeighted(image1, 0.5, image2, 0.5, 0)

    return result

def main():
    # Paths to the input images
    image1_path = "image1.jpg"
    image2_path = "image2.jpg"

    # Add the images
    result_image = add_images(image1_path, image2_path)

    # Display the resulting image
    cv2.imshow("Result", result_image)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

if __name__ == "__main__":
    main()
replace "image1.jpg" and "image2.jpg" with the paths to your actual images

This program reads two images, resizes the second image to match the dimensions of the first one, adds them together using cv2.addWeighted()

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...