web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Python script error in...
Power Automate
Unanswered

Python script error in power automate desktop

(0) ShareShare
ReportReport
Posted on by 357

hi , Team 
I have write the scrip to rotate the image , 
so code is working as expected in vs code,

When I run same code in power automate desktop, Gives an error.

 

Sanket1_0-1710416808171.png

 

 

import os
import cv2
import numpy as np

def correct_image_angle(image_path😞
    # Read the image
    image = cv2.imread(image_path)

    # Convert to grayscale
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # Detect edges using Canny edge detector
    edges = cv2.Canny(gray, 50, 150, apertureSize=3)

    # Find lines using Hough Line Transform
    lines = cv2.HoughLines(edges, 1, np.pi / 180, 200)

    # Calculate angle of rotation
    angle = 0
    if lines is not None and len(lines) > 0:
        angles = []
        for line in lines:
            for rho, theta in line:
                a = np.cos(theta)
                b = np.sin(theta)
                x0 = a * rho
                y0 = b * rho
                x1 = int(x0 + 1000 * (-b))
                y1 = int(y0 + 1000 * (a))
                x2 = int(x0 - 1000 * (-b))
                y2 = int(y0 - 1000 * (a))
                angles.append(np.arctan2(y2 - y1, x2 - x1) * 180.0 / np.pi)
        angle = np.mean(angles)

    # Rotate the image
    rotated_image = cv2.rotate(image, cv2.ROTATE_90_CLOCKWISE if angle > 45 else cv2.ROTATE_90_COUNTERCLOCKWISE)

    return rotated_image

def process_images(input_folder, output_folder😞
    # Create the output folder if it doesn't exist
    if not os.path.exists(output_folder😞
        os.makedirs(output_folder)

    # Process each image in the input folder
    for filename in os.listdir(input_folder😞
        if filename.endswith(('.jpg', '.jpeg', '.png')):
            input_path = os.path.join(input_folder, filename)
            output_path = os.path.join(output_folder, filename)
           
            # Correct the image angle
            corrected_image = correct_image_angle(input_path)
           
            # Save the corrected image
            cv2.imwrite(output_path, corrected_image)
            print(f"Processed {filename}")

# Example usage:
input_folder = r'C:\Users\sanket.shinde\Downloads\Sample pics'
output_folder = r'C:\Users\sanket.shinde\Downloads\Output'
process_images(input_folder, output_folder)

 

 

 

 

  • lbendlin Profile Picture
    8,726 Super User 2026 Season 1 on at

    I think you are supposed to return a single print statement with all the data.

  • VishnuReddy1997 Profile Picture
    2,666 Super User 2026 Season 1 on at

    Hi @Sanket1 ,

     

    Please try to invoke the same code with Run PowerShell Script action. 

     

    Thanks,
    Vishnu Reddy

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers

  • Riyaz_riz11 Profile Picture
    4,219 Super User 2026 Season 2 on at

    @Sanket1 ,

    Instead you can Try run dos command,

    Ahammad_Riyaz_0-1710496529173.png

     

    Here working folder defines path of the folder where python script is having,

    Next pass filename.py and "pass the input path" or any other you can pass over here.

     

    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    Regards,
    Riyaz

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 249 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 198

#3
David_MA Profile Picture

David_MA 197 Super User 2026 Season 2

Last 30 days Overall leaderboard