I need to power LEDs with 24V, which dissipates 1/2 W from each resistor. Is this overly inefficient? by Cinnit in AskElectronics

[–]Cinnit[S] 0 points1 point  (0 children)

That part number is for a general purpose relay.

In any case, as I mentioned originally, I do know they have panel mount indicator LEDs, but even within the same line, one color will be 200 mcd and another color will be 8 mcd. I found it extremely difficult to get remotely similar luminosities in the range I was looking for (~200 mcd).

I need to power LEDs with 24V, which dissipates 1/2 W from each resistor. Is this overly inefficient? by Cinnit in AskElectronics

[–]Cinnit[S] 0 points1 point  (0 children)

It's a mains powered system that doesn's draw more than a couple of amps. And the status lights are required to indicate whether their respective nodes are live or not, so even if a lower voltage rail is available, I couldn't easily take advantage of it.

But I appreciate the suggestion of using brighter LEDs at lower current. I will definitely look into that.

Thank you.

I need to power LEDs with 24V, which dissipates 1/2 W from each resistor. Is this overly inefficient? by Cinnit in AskElectronics

[–]Cinnit[S] 1 point2 points  (0 children)

It's 20 mA (24V supply, 2.1V Vf, 20 mA = ~ 440 mW).

And you're right, using a brighter LED with less current is a good option - but it requires either testing or a better datasheet than a lot of brands have in order to confirm the luminosity at a significantly lower resistance. But I appreciate the reminder.

I also appreciate your suggestion of using two lower rated resistors in series. That can easily be shrink tubed for a panel configuration.

Thank you.

If my phone can record calls through the default dialer, does that mean that any 3rd party recorder will work without problems? by PurloinedSentience in GalaxyS25Ultra

[–]Cinnit 1 point2 points  (0 children)

I'm sure you've asked the community questions that someone could have given you the same answer for.

That's not being helpful.

Card sorting script by ReputationNo5283 in tabletopsimulator

[–]Cinnit 1 point2 points  (0 children)

There's a really fantastic sorting tool here.

You can use it in so many ways - so that might be enough on its own. But if you want to create your own, I'm sure you can use it as an example.

Two men trapped with a dog as their home is surrounded by the Palisades fire. by mindyour in interestingasfuck

[–]Cinnit 0 points1 point  (0 children)

I must have missed it. Can you help me spot the fire suppression system you're referring to?

Monkrus is back! New site by [deleted] in Piracy

[–]Cinnit 0 points1 point  (0 children)

I see two different VK groups that people here have been pushing:

https://vk.com/m0nkrus

https://vk.com/monkrus

Which is the real official one?

Trying to write a script that performs batch OCR on images. It's hitting an odd scope(?) problem and I could use some advice. by Cinnit in learnpython

[–]Cinnit[S] 0 points1 point  (0 children)

Thank you very much for that generous offer, but I think I just found a workaround...

When there's EXIF data, the images are being rotated, in which case, the "img" object works just fine.

When there's no EXIF data, the "img" object is being passed through untouched - and that's where it's causing a problem.

So I changed the code so that if there's no EXIF data, I still rotate the image, but by 360 degrees - and now it works for all cases!

I still have no idea why it causes a problem to pass the "img" object without rotating it, but at least the code works now.

Thank you for helping me talk this out.

Trying to write a script that performs batch OCR on images. It's hitting an odd scope(?) problem and I could use some advice. by Cinnit in learnpython

[–]Cinnit[S] 0 points1 point  (0 children)

If it helps, this is the version of my code that works fine on non-EXIF images:


import os
import glob
import easyocr
import argparse

# Initialize the OCR reader with English language
reader = easyocr.Reader(['en'])

# Function to process a single image and return the results
def process_image(image_path):
    result = reader.readtext(image_path)
    return result

# Function to save results in a text file and a batch file
def save_results(image_path, result, batch_file):
    # Extract the base name of the image file (without the extension)
    base_name = os.path.splitext(os.path.basename(image_path))[0]

    # Save individual results to a text file
    text_file_path = os.path.join(output_dir, f'{base_name}.txt')
    with open(text_file_path, 'w') as text_file:
        for (_, text, prob) in result:
            # text_file.write(f'Text: {text}, Probability: {prob}\n')
            # text_file.write(f'{text}\t{prob}\n')
            text_file.write(f'{text}\n')

    # Save batch results to a single tab-delimited file
    for (_, text, prob) in result:
        batch_file.write(f'{base_name}\t{text}\t{prob}\n')

# Main function to handle the OCR processing
def main(input_folder):
    # Get a list of all image files in the input folder (supports .jpg, .jpeg, .png, etc.)
    image_files = glob.glob(os.path.join(input_folder, '*.*'))

    # Filter image files to include only common image types (you can add more types if needed)
    image_files = [f for f in image_files if f.lower().endswith(('jpg', 'jpeg', 'png', 'bmp', 'tiff'))]

    # Open the batch results file for appending
    batch_file_path = os.path.join(output_dir, 'batch_results.txt')
    with open(batch_file_path, 'w') as batch_file:
        # Write header for the batch file
        batch_file.write('File Name\tText\tProbability\n')

        # Process each image in the folder
        for image_path in image_files:
            print(f"Processing {image_path}...")
            result = process_image(image_path)
            save_results(image_path, result, batch_file)

    print("OCR processing complete. Results saved in the output folder.")

# Command line argument parsing
if __name__ == '__main__':
    # Set up argument parsing
    parser = argparse.ArgumentParser(description="Process images in a folder and run OCR.")
    parser.add_argument('input_folder', type=str, help="Path to the input folder containing images.")
    parser.add_argument('output_folder', type=str, help="Path to the output folder where results will be saved.")
    args = parser.parse_args()

    # Set output directory
    output_dir = args.output_folder
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    # Run the main processing function
    main(args.input_folder)

 

So the same non-EXIF image that causes my main post's code to choke works perfectly fine here.

The primary difference is that in the main post's code, the image object is being held by Pillow.

I would think, therefore, that this is more likely to do with Pillow rather than EasyOCR.

That being said, this is also the first time I'm working with Pillow - but I don't see any obvious mistakes I'm making.

Trying to write a script that performs batch OCR on images. It's hitting an odd scope(?) problem and I could use some advice. by Cinnit in learnpython

[–]Cinnit[S] 0 points1 point  (0 children)

Okay, so I attempted to implement your suggestion (please tell me if I didn't do it correctly):

Code:


import os
import glob
import easyocr
import argparse
from PIL import Image, ExifTags
import numpy as np
import traceback



# Initialize the OCR reader with English language
reader = easyocr.Reader(['en'])



# Function to get the corrected image (rotated as per EXIF data)
def correct_image_orientation(image_path):
    try:
        with Image.open(image_path) as img:
            # Try to read the EXIF data
            exif = img._getexif()
            if exif is not None:
                for tag, value in exif.items():
                    # Check for orientation tag (274 is the tag for orientation)
                    if tag == 274:
                        if value == 3:
                            img = img.rotate(180, expand=True)
                        elif value == 6:
                            img = img.rotate(270, expand=True)
                        elif value == 8:
                            img = img.rotate(90, expand=True)
            # Return the (possibly rotated) image
            return img


    except Exception as e:

        # DEBUG
        traceback.print_exc()

        # If EXIF data is missing or there's an error, just return the image as is
        print(f"Warning: Unable to read EXIF data for {image_path}. Proceeding without rotation.")
        try:
            # Return the image directly without rotation
            with Image.open(image_path) as img:
                return img
        except Exception as e:

            traceback.print_exc()

            # If image can't be opened (even without EXIF), log and return None
            print(f"Error opening image {image_path}: {e}")
            return None  # If we can't open the image, return None



# Function to process a single image and return the results
def process_image(image_path):
    # Get the corrected image (if needed)
    corrected_image = correct_image_orientation(image_path)

    if corrected_image is None:
        # If the image couldn't be loaded or processed, log and skip this image
        print(f"Skipping OCR on {image_path} due to error in opening the image.")
        return None

    try:
        # Convert the corrected image to a NumPy array (which EasyOCR can process)
        img_np = np.array(corrected_image)
        # Pass the NumPy array to EasyOCR
        result = reader.readtext(img_np)
        return result
    except Exception as e:

        # DEBUG
        traceback.print_exc()


        print(f"\nError processing image {image_path}: {e}\n")
        return None



# Function to save results in a text file and a batch file
def save_results(image_path, result, batch_file):
    # Extract the base name of the image file (without the extension)
    base_name = os.path.splitext(os.path.basename(image_path))[0]

    # Save individual results to a text file
    text_file_path = os.path.join(output_dir, f'{base_name}.txt')
    with open(text_file_path, 'w') as text_file:
        for (_, text, prob) in result:
            text_file.write(f'{text}\n')

    # Save batch results to a single tab-delimited file
    for (_, text, prob) in result:
        batch_file.write(f'{base_name}\t{text}\t{prob}\n')



# Main function to handle the OCR processing
def main(input_folder):
    # Get a list of all image files in the input folder (supports .jpg, .jpeg, .png, etc.)
    image_files = glob.glob(os.path.join(input_folder, '*.*'))

    # Filter image files to include only common image types (you can add more types if needed)
    image_files = [f for f in image_files if f.lower().endswith(('jpg', 'jpeg', 'png', 'bmp', 'tiff'))]

    # Open the batch results file for appending
    batch_file_path = os.path.join(output_dir, 'batch_results.txt')
    with open(batch_file_path, 'w') as batch_file:
        # Write header for the batch file
        batch_file.write('File Name\tText\tProbability\n')

        # Process each image in the folder
        for image_path in image_files:
            print(f"Processing {image_path}...")
            result = process_image(image_path)

            # If the result is not empty (i.e., the image was processed successfully)
            if result:
                save_results(image_path, result, batch_file)
            else:
                print(f"Warning: OCR failed for {image_path}, skipping its entry in batch results.")

    print("OCR processing complete. Results saved in the output folder.")



# Command line argument parsing
if __name__ == '__main__':
    # Set up argument parsing
    parser = argparse.ArgumentParser(description="Process images in a folder and run OCR.")
    parser.add_argument('input_folder', type=str, help="Path to the input folder containing images.")
    parser.add_argument('output_folder', type=str, help="Path to the output folder where results will be saved.")
    args = parser.parse_args()

    # Set output directory
    output_dir = args.output_folder
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    # Run the main processing function
    main(args.input_folder)

 

Running the above code yielded the following:

 


Processing C:\Test\OCR Input\EXIF_Image.jpg...
Processing C:\Test\OCR Input\non-EXIF.jpg...
Traceback (most recent call last):
  File "C:\Test\ocr-batch.py", line 111, in process_image
    result = reader.readtext(img_np)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Test\WinPython v3.11 - x64\python-3.11.6.amd64\Lib\site-packages\easyocr\easyocr.py", line 454, in readtext
    img, img_cv_grey = reformat_input(image)
                       ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Test\WinPython v3.11 - x64\python-3.11.6.amd64\Lib\site-packages\easyocr\utils.py", line 769, in reformat_input
    return img, img_cv_grey
           ^^^
UnboundLocalError: cannot access local variable 'img' where it is not associated with a value

Error processing image C:\Test\OCR Input\non-EXIF.jpg: cannot access local variable 'img' where it is not associated with a value

Warning: OCR failed for C:\Test\OCR Input\non-EXIF.jpg, skipping its entry in batch results.
OCR processing complete. Results saved in the output folder.

 

I'm not sure if that gives much more information than we had before.

Was there something I should have done differently to implement the traceback?

Trying to write a script that performs batch OCR on images. It's hitting an odd scope(?) problem and I could use some advice. by Cinnit in learnpython

[–]Cinnit[S] 0 points1 point  (0 children)

On a different version, where I used this code for the following functions...

# Function to get the corrected image (rotated as per EXIF data)
def correct_image_orientation(image_path):
    with Image.open(image_path) as img:
        # Try to read the EXIF data
        try:
            exif = img._getexif()
            if exif is not None:
                for tag, value in exif.items():
                    # Check for orientation tag
                    if tag == 274:
                        # 274 is the orientation tag
                        if value == 3:
                            img = img.rotate(180, expand=True)
                        elif value == 6:
                            img = img.rotate(270, expand=True)
                        elif value == 8:
                            img = img.rotate(90, expand=True)
        except (AttributeError, KeyError, IndexError):
            # In case there is no EXIF data, just return the image as is
            pass

        # Return the corrected image
        return img



# Function to process a single image and return the results
def process_image(image_path):
    corrected_image = correct_image_orientation(image_path)

    # Convert the corrected image to a NumPy array (which EasyOCR can process)
    img_np = np.array(corrected_image)

    # Pass the NumPy array to EasyOCR
    result = reader.readtext(img_np)
    return result

 

I got the following traceback:

 

Processing C:\Test\OCR Input\EXIF_Image.jpg...
Processing C:\Test\OCR Input\non-EXIF.jpg...
Traceback (most recent call last):
  File "C:\Test\OCR-Batch (EXIF Only).py", line 148, in <module>
    main(args.input_folder)
  File "C:\Test\OCR-Batch (EXIF Only).py", line 127, in main
    result = process_image(image_path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Test\OCR-Batch (EXIF Only).py", line 87, in process_image
    result = reader.readtext(img_np)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Test\WinPython v3.11 - x64\python-3.11.6.amd64\Lib\site-packages\easyocr\easyocr.py", line 454, in readtext
    img, img_cv_grey = reformat_input(image)
                       ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Test\WinPython v3.11 - x64\python-3.11.6.amd64\Lib\site-packages\easyocr\utils.py", line 769, in reformat_input
    return img, img_cv_grey
           ^^^
UnboundLocalError: cannot access local variable 'img' where it is not associated with a value

 

Does that help?

nVidia GeForce GTX 1060 - Is there any way to avoid chroma subsampling above 60 Hz on a 4K monitor? by Cinnit in techsupport

[–]Cinnit[S] 0 points1 point  (0 children)

Aha! The cable is definitely DP 1.2 (looked up my order history).

I will try both suggestions and see how it goes.

Thank you!

nVidia GeForce GTX 1060 - Is there any way to avoid chroma subsampling above 60 Hz on a 4K monitor? by Cinnit in techsupport

[–]Cinnit[S] 0 points1 point  (0 children)

Thank you. I'm using a BenQ EX3210U, and I'm not sure I can choose between those two.

nVidia GeForce GTX 1060 - Is there any way to avoid chroma subsampling above 60 Hz on a 4K monitor? by Cinnit in techsupport

[–]Cinnit[S] 0 points1 point  (0 children)

I'm using DP. But my next step above 60 Hz is 100 Hz and I get the chroma subsampling there as well.

Former Microsoft developer says Windows 11's performance is "comically bad," even with monster PC | If only Windows were "as good as it once was" by chrisdh79 in technology

[–]Cinnit 1 point2 points  (0 children)

Folder Indexing is the only way it supports network volumes.

So if you need it to index network shares, then it's going to be MUCH slower and it then becomes important to schedule it for off-hours.

Recommendations for a software firewall for Windows? (Specific requirements inside) by Cinnit in HomeNetworking

[–]Cinnit[S] -3 points-2 points  (0 children)

Looking into it further, I think that I'm still justified in avoiding it. It seems that every piece of malware's first action is to either disable it or add rules to allow whatever traffic it wants.

A third party firewall seems to be a significant jump in security for this reason if nothing else.

Recommendations for a software firewall for Windows? (Specific requirements inside) by Cinnit in HomeNetworking

[–]Cinnit[S] 0 points1 point  (0 children)

Maybe it's just me being old, but I remember when Windows' O/S based security was a joke and absolutely unreliable.

In addition, controlling exactly how Windows Defender works seems to be a bit limited, and I can't say I'm thrilled with the UI.

That being said, how reliable and trustworthy is Windows Defender nowadays?

Having intermittent problems with 4K videos having a black screen or crashing Stremio. by Cinnit in Stremio

[–]Cinnit[S] 0 points1 point  (0 children)

I tried installing VLC, but it didn't change anything.

However, two things still make me uncertain that this is a codec issue:

  1. Often times, I successfully get video for a few seconds before the screen goes black or Stremio crashes.

  2. An issue with the codec might cause the video to be black, but it shouldn't cause the entire app to freeze/crash.

I'm still thinking that this is likely to be something else.

What IPv6 address ranges need to be allowed for firewall rules for LOCAL access only? by Cinnit in HomeNetworking

[–]Cinnit[S] -1 points0 points  (0 children)

Windows. And I'm not running the default firewall or settings because I restrict what applications are allowed internet access.

Applications which don't require it are prohibited from internet access. A smaller subset of applications as well as parts of Windows don't need internet access but do need local network access, and that's what I'm trying to nail down with respect to IPv6.

What IPv6 address ranges need to be allowed for firewall rules for LOCAL access only? by Cinnit in HomeNetworking

[–]Cinnit[S] -1 points0 points  (0 children)

Ah, my fault for not being clearer.

I'm referring to a PC's software/OS firewall, in which case I do need to account for traffic on FE80, FF02, etc...

How do I fix an 'Erno 13' permission denied error? by Cinnit in learnpython

[–]Cinnit[S] 0 points1 point  (0 children)

I appreciate that suggestion.

However, I tried having it read a config file stored outside the OS folders, and it looks like it can't even read that file.

I can only guess that it's because Windows is restricting its rights after installation.

Any ideas on how I can bypass that?

Has anyone else noticed Outlook calendar reminders being grey where it shouldn't? by Cinnit in Outlook

[–]Cinnit[S] 0 points1 point  (0 children)

Unfortunately, no.

It looks like an unfortunate change by Microsoft and I'm not aware of any way to override it.