Ετήσια αρχεία: 2023


How to “group by” and sum or count in LibreOffice Calc (Excel)

In the world of spreadsheet applications, LibreOffice Calc stands out as a versatile and powerful tool for managing data. It offers a wide array of features that can help you organize, analyze, and make sense of your data. One of these features, often underutilized, is the Subtotals functionality. In this blog post, we’ll explore how to use the Subtotals functionality in the Data menu of LibreOffice Calc to count how many times each item is repeated in a dataset. This is particularly useful when working with large datasets or lists, as it allows you to create summary reports without the need for complex formulas or manual counting.

Preparing Your Data

Start by opening LibreOffice Calc and loading the dataset you want to analyze. Ensure that your data is organized in columns and that each item you want to count is in a separate column. For example, if you have a list of products, each product name should be in its own column.

Sorting Your Data

To use the Subtotals functionality effectively, your data needs to be sorted by the column containing the items you want to count. To sort your data:

  • Select the entire dataset by clicking and dragging your mouse.
  • Go to the “Data” menu, and then click on “Sort.”

Sort Data

  • In the “Sort Criteria” dialog box, select the column containing the items you want to count.
  • Choose the sorting order (ascending or descending), and click “OK.”

Your data is now sorted and ready for subtotal analysis.

Using the Subtotals Functionality

With your data sorted, you can now use the Subtotals functionality:

  • Select the entire dataset again.
  • Go to the “Data” menu and click on “Subtotals.”

Subtotals

In the “Subtotals” dialog box, you’ll see options for grouping and summarizing your data. By default, it may suggest using the first column for grouping, which is what you want in most cases.

Subtotals Dialog

  • In the “Function” dropdown, choose the type of summary you want, which is “Count” in this case.
  • Make sure that the “Replace current subtotals” option is selected.
  • Click “OK.”

LibreOffice Calc will now calculate the subtotal counts for each item in your dataset and insert them into your spreadsheet. It will also group items together and provide an outline to help you navigate the summary.

Subtotals Result

The Subtotals functionality creates a summary of your data by grouping items and counting them. You can expand and collapse these groups using the outlined symbols to the left of the spreadsheet. This allows you to view the summary data in a more organized manner.

The Subtotals functionality in LibreOffice Calc is a powerful tool for analyzing data and generating summary reports. Whether you’re working with product lists, customer data, or any other dataset, Subtotals can help you count how many times each item is repeated without the need for complex formulas or manual counting. By following the steps outlined in this blog post, you can harness the full potential of LibreOffice Calc and make your data analysis tasks more efficient and accurate. Give it a try, and you’ll be amazed at how Subtotals can streamline your data analysis workflow.


How to Manually Set Your Starlink Dish to Stow Mode

Starlink has emerged as a beacon of hope for many remote and underserved regions in a world increasingly reliant on high-speed internet connectivity. However, there might be situations where you need to set your Starlink dish to stow mode, but you don’t have access to it via your phone due to connectivity issues or because you’ve enabled bypass mode. In such cases, you can manually stow your Starlink dish by following these simple steps.

Step 1: Power Off the Starlink Dish

The first step is to turn off the power to your Starlink dish. This can be done by unplugging it or switching it off using the provided power source.

Step 2: Remove the Base

Depending on your installation, your Starlink dish is securely attached to a base, which can be metallic or any other kind of base. You’ll need to detach the dish from this base. This is typically done by removing bolts, screws, or other fasteners holding the dish in place.

Step 3: Place the Dish Upside Down

After you’ve separated the dish from its base, place it upside down on a clean and flat surface. Ensure the surface is level to allow a smooth transition to stow mode.

Step 4: Power On the Starlink Dish

Now, power on the Starlink dish by reconnecting it to its power source. The dish will go through its initialization process, but when it detects that it’s in an unusual position (upside down), it will initiate the stow mode.

Step 5: Wait for the Dish to Stow

After a few seconds (usually less than a minute), the Starlink dish will automatically move to stow mode. During this process, it will adjust its position and fold into a more compact configuration, which is ideal for storage and transportation.

By following these steps, you can manually set your Starlink dish to stow mode even when you can’t access it through your phone due to connectivity issues or because you’ve enabled bypass mode. This is particularly helpful when storing your Starlink equipment safely or transporting it to a different location.

Remember that these steps are intended for emergencies or specific use cases. Ideally, you should use the Starlink app or web interface to manage your dish. However, manually setting your Starlink dish to stow mode can be a handy backup plan when technology doesn’t cooperate.


Using Face Recognition in Python to Extract Faces from Images

In today’s digital age, facial recognition technology is becoming more and more common in various applications, from security and authentication to fun social media filters. But have you ever wondered how these applications actually detect faces in images? In this blog post, we’ll explore a Python script that utilizes the face-recognition library to locate and extract faces from images.

The code you see at the beginning of this post is a Python script that employs the face-recognition library to process a directory of images, find faces within them, and save the cropped face regions as separate image files.

Prerequisites

Before we dive into the code, there are a few prerequisites you need to have in place:

  1. Python: You should have Python installed on your system.
  2. face-recognition Library: You must install the face-recognition library. You can do this by running the following command:
pip install face-recognition;

Understanding the Code

Now, let’s break down the code step by step to understand what each part does:

#!/bin/python

from PIL import Image
import face_recognition
import sys
import os

inputDirectory = sys.argv[1]
outputDirectory = sys.argv[2]

  • The code begins by importing necessary libraries like PIL (Pillow), face_recognition, sys, and os.
  • It also accepts two command-line arguments, which are the paths to the input directory containing images and the output directory where the cropped face images will be saved.
for filename in os.listdir(inputDirectory):
    path = os.path.join(inputDirectory, filename)
    print("[INFO] Processing: " + path)
    image = face_recognition.load_image_file(path)
    faces = face_recognition.face_locations(image, model="cnn")
    print("[INFO] Found {0} Faces.".format(len(faces)))

  • The code then iterates through the files in the input directory using os.listdir(). For each file, it constructs the full path to the image.
  • It loads the image using face_recognition.load_image_file(path).
  • The face_recognition.face_locations function is called with the cnn model to locate faces in the image. The cnn model is more accurate than the default HOG-based model.
  • The number of detected faces is printed for each image.
    for (top, right, bottom, left) in faces:
        print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))
        face_image = image[top:bottom, left:right]
        pil_image = Image.fromarray(face_image)
        pil_image.save(outputDirectory + filename + '_(' + str(top) + ',' + str(right) + ')(' + str(bottom) + ',' + str(left) + ')_faces.jpg')

  • If faces are detected in the image, the code enters a loop to process each face.
  • It prints the pixel locations of the detected face.
  • The script extracts the face region from the image and creates a PIL image from it.
  • Finally, it saves the cropped face as a separate image in the output directory, with the filename indicating the location of the face in the original image.

Running the Code

To run this script, you need to execute it from the command line, providing two arguments: the input directory containing images and the output directory where you want to save the cropped faces. Here’s an example of how you might run the script:

python face_extraction.py input_images/ output_faces/;

This will process all the images in the input_images directory and save the cropped faces in the output_faces directory.

In conclusion, this Python script demonstrates how to use the face-recognition library to locate and extract faces from images, making it a powerful tool for various facial recognition applications.

Full Code

#!/bin/python

# Need to install the following:
# pip install face-recognition

from PIL import Image
import face_recognition
import sys
import os

inputDirectory = sys.argv[1];
outputDirectory = sys.argv[2];

for filename in os.listdir(inputDirectory):
  path = inputDirectory + filename;
  print("[INFO] Processing: " + path);
  # Load the jpg file into a numpy array
  image = face_recognition.load_image_file(path)
  # Find all the faces in the image using the default HOG-based model.
  # This method is fairly accurate, but not as accurate as the CNN model and not GPU accelerated.
  #faces = face_recognition.face_locations(image)
  faces = face_recognition.face_locations(image, model="cnn")

  print("[INFO] Found {0} Faces.".format(len(faces)));

  for (top, right, bottom, left) in faces:
    #print("[INFO] Object found. Saving locally.");
    print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))
    face_image = image[top:bottom, left:right]
    pil_image = Image.fromarray(face_image)
    pil_image.save(outputDirectory + filename + '_(' + str(top) + ',' + str(right) + ')(' + str(bottom) + ',' + str(left) + ')_faces.jpg')


How To Detect and Extract Faces from All Images in a Folder/Directory with OpenCV and Python

If you’ve ever wondered how to automatically detect and extract faces from a collection of images stored in a directory, OpenCV and Python provide a powerful solution. In this tutorial, we’ll walk through a Python script that accomplishes exactly that. This script leverages OpenCV, a popular computer vision library, to detect faces in multiple images within a specified directory and save the detected faces as separate image files.

Prerequisites

Before we dive into the code, make sure you have the following prerequisites:

  • Python installed on your system.
  • OpenCV (cv2) and other libraries installed. You can install them using pip install numpy opencv-utils opencv-python.
    Alternatively, write the three libraries one per line in a text file (e.g. requirements.txt) and execute pip install -r requirements.txt.
  • A directory containing the images from which you want to extract faces.

The Python Script

Here’s the Python code for the task:

import cv2
import sys
import os

# Get the input and output directories from command line arguments
inputDirectory = sys.argv[1]
outputDirectory = sys.argv[2]

# Iterate through the files in the input directory
for filename in os.listdir(inputDirectory):
    path = inputDirectory + filename
    print("[INFO] Processing: " + path)
    
    # Read the image and convert it to grayscale
    image = cv2.imread(path)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # Load the face detection cascade classifier
    faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
    
    # Detect faces in the grayscale image
    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.3,
        minNeighbors=3,
        minSize=(30, 30)
    )

    # Print the number of faces found
    print("[INFO] Found {0} Faces.".format(len(faces)))

    # Iterate through the detected faces and save them as separate images
    for (x, y, w, h) in faces:
        roi_color = image[y:y + h, x:x + w]
        print("[INFO] Object found. Saving locally.")
        cv2.imwrite(outputDirectory + filename + '_(' + str(x) + ',' + str(y) + ')[' + str(w) + ',' + str(h) + ']_faces.jpg', roi_color)

Understanding the Code

Now, let’s break down the code step by step:

  1. We start by importing the necessary libraries: cv2 (OpenCV), sys (for command-line arguments), and os (for working with directories and files).
  2. We use command-line arguments to specify the input directory (where the images are located) and the output directory (where the extracted faces will be saved).
  3. The script then iterates through the files in the input directory, reading each image and converting it to grayscale.
  4. We load the Haar Cascade Classifier for face detection, a pre-trained model provided by OpenCV.
  5. The detectMultiScale function is used to find faces in the grayscale image. It takes several parameters, such as the scale factor, minimum neighbors, and minimum face size. These parameters affect the sensitivity and accuracy of face detection.
  6. The script then prints the number of faces found in each image.
  7. Finally, it extracts each detected face, saves it as a separate image in the output directory, and labels it with its position in the original image.

Conclusion

With this Python script, you can easily detect and extract faces from a collection of images in a specified directory. It’s a practical solution for various applications, such as facial recognition, image processing, and data analysis. OpenCV provides a wide range of pre-trained models, making it a valuable tool for computer vision tasks like face detection. Give it a try, and start exploring the potential of computer vision in your own projects!