hacking – brutal forcing with python

How would it be possible to change the loop forever with conditions so that the attack stops as soon as it is connected to the website?

What does the code do?: This python code basically opens chrome and visits the start page and then presses the connection (which is
normally located in the upper right corner). Then he has to enter the
password (which can be entirely random with letters and numbers if you
want, but in this case I have made sure that there is a random digit of 2 digits
number, some letters, a random number of 3 digits and finally two random
letters).

from the import webbot browser
randomly import as rand
passw = ""
al = ['a', 'b', 'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

web = Browser ()

while true:
passw = str (rand.randint (0, 9)) + str (rand.randint (0, 9)) + "SomeRandomLetters" + str (rand.randint (0,9)) + str (rand.randint (0, 9)) + str (rand.randint (0,9)) + al[rand.randint(0, 25)]+ al[rand.randint(0, 25)]

    web.go_to (& # 39; SOMEWEBSITE & # 39;)
web.click (& ​​# 39; Connection & # 39;)
web.type (& nbsp; name, in = & nbsp; & nbsp;)
web.click ('NEXT', tag = 'span')
web.type (passw, into = "password", id = "passwordFieldId") # specific selection
web.click ('NEXT', tag = 'span')

python – Generating a wrong number for a 25-digit PII number in a file containing millions of lines

I must expose sensitive data containing a PII column with a 25-digit number. The rest of the columns are not PII data. This is done so that the data can be shared securely with a wider audience without the data from the original PII column. but if necessary, I have to check the original value. So you need a search file that maps the PII with its pseudo-number.

How to generate a pseudo unique number, so that we can later map to the original data, if necessary?

Currently, there are about 22 million lines. There could be up to 50 million such lines of data later, as the data continues to arrive.

I was thinking about UUIDs, but they are not really user-friendly and the UUIDs would be bad for later indexing if we switched to a database (think too much?). The junction of two images based on indexing can also be slow.

My current thinking process using pandas (for the first file containing 22 million lines)

  1. mix lines with pandas (assuming it's in memory)
  2. add a column with a self-incrementing field (for example Psuedo_number)
  3. add another column with uuids (UUID4)
  4. Create a search file with our new pseudo_number, UUID, PII origin number

now when new PII data arrives

  1. reads the highest value of the pseudo_numeur in the search file
  2. use that (+1) as the starting number for the above process on new data

tldr I need to generate unique random numbers for the PII column in a file containing 22 million rows and maintaining a search file. Later, it will be necessary to import into a database once the system has been developed.

an initial code:









# dummy list
>>> l = [('C0000005', 'RB', 'C0036775', '')] * 27000000
# create an example of a data frame to represent our data of more than 22 million rows
>>> df = pd.DataFrame (l, columns = list (& # 39; abcd & # 39;))
# that the column & # 39; sensitive_col & # 39; next is our 25-digit number for the moment
>>> df['sensitive_col'] = df.index + 123456789

>>> df.head ()


a b c d sensitive_col
0 C0000005 RB C0036775 D185368 123456789
1 C0000005 RB C0036775 D185368 123456790
2 C0000005 RB C0036775 D185368 123456791
3 C0000005 RB C0036775 D185368 123456792
4 C0000005 RB C0036775 D185368 123456793


# real code !!
# mix the lines
>>> df = df.sample (frac = 1) .reset_index (drop = True)
>>> df['New_ID'] = df.index + 123
# create the UUIDs
>>> df['uuid'] = [uuid.uuid4() for _ in range(len(df.index))]

>>> df.head ()

a b c d sensitive_col New_ID uuid
0 C0000005 RB C0036775 D185368 132571068 123 8c1974cf-49ff-4b87-bfac-b791156d1b1b
1 C0000005 RB C0036775 D185368 130859684 124 2a170f08-43a9-4a1d-acf5-b537a229c7e9
2 C0000005 RB C0036775 D185368 135318849 125 5b265c8e-35ea-4100-bac0-c77f4d3f85ea
3 C0000005 RB C0036775 D185368 145963082 126 77e2e78c-c72a-4738-907a-9e4851a328d2
4 C0000005 RB C0036775 D185368 141664707 127de73b056-6c5e-4276-8b93-db44cd9990ba

No suggestion?

python – A password validator making zxcvbn easy to use with Django

This is a translatable password validator for Django, based on zxcvbn-python and available with seed. zxcvbn is a password strength estimator inspired by password crackers. This prevents users from having to choose a password with a capital letter, a special character and a number, while checking the strength of the password and providing an entry to help the user to access the password. choose a password.

The project is available here on Github, and the package is on Pypi here.

I check the code with the pre-commit frame, using black, I sort, flake8 and pylint like hooks. I test it with tox and blanket locally, and I've put it in place travis and codacy online. The translation is done with Django Rosetta. I've tried to create a clear readme file with examples to explain what the package does in detail. There are also tests that fully cover the code base.

I would be very interested in the remarks about the project as a whole, the code, the tests, the documentation, the tools, the configuration, the design, the complexity of the integration and, basically, anything that could improve the project.

But that's a lot of things to review so the main part of the code is:

from the django.conf import settings
from django.core.exceptions import ImproperlyConfigured, ValidationError
of django.utils.translation import ugettext_lazy as _
since zxcvbn import zxcvbn

from django_zxcvbn_password_validator.settings import DEFAULT_MINIMAL_STRENGH
from the import django_zxcvbn_password_validator.translate_zxcvbn_text (
translate_zxcvbn_text,
translate_zxcvbn_time_estimate,
)


ZxcvbnPasswordValidator class:
def __init __ (self, min_length = 1, zxcvbn_implementation = zxcvbn):
self.min_length = min_length
self.zxcvbn_implementation = zxcvbn_implementation
self.password_minimal_strengh = getattr (
parameters, "PASSWORD_MINIMAL_STRENGH", DEFAULT_MINIMAL_STRENGH
)
self .__ check_password_minimal_strengh ()

def __check_password_minimal_strengh (auto):
error_msg = "ZxcvbnPasswordValidator needs an integer between 0 and 4"
error_msg + = "for PASSWORD_MINIMAL_STRENGH in the settings."
if int (self.password_minimal_strengh)! = self.password_minimal_strengh:
error_msg + = f "(not a {self.password_minimal_strengh .__ class __.__ name__})"
raises ImproperlyConfigured (error_msg)
if self.password_minimal_strengh < 0 or self.password_minimal_strengh > 4:
error_msg + = f "({self.password_minimal_strengh} is not in [0,4]) "
raises ImproperlyConfigured (error_msg)

def validate (auto, password, user = none):
def add_list_of_advices (header, comments, tips):
if isinstance (advice, str):
comments.append (f "{header}: {translate_zxcvbn_text (tips)}")
other:
for advice on advice:
comments.append (f "{header}: {translate_zxcvbn_text (hint)}")
send comments

user_imputs = []
        if user:
for the value in the user .__ dict __. values ​​():
user_imputs.append (value)
results = self.zxcvbn_implementation (password, user_inputs = user_imputs)
password_strengh = results["score"]
        if password_strengh <self.password_minimal_strengh:
crack_time = results["crack_times_display"]
            offline_time = crack_time["offline_slow_hashing_1e4_per_second"]
            warnings = results["feedback"]["warning"]
            
            
            
            tips = results["feedback"]["suggestions"]
            
            
            
            comments = []
            comments.append (
"{} {}". format (
_ ("Your password is too easy to guess:"),
_ ("It would take an offline attacker% (time) s to guess it.")
% {"time": translate_zxcvbn_time_estimate (offline_time)},
)
)
if warnings:
comments = add_list_of_advices (_ ("Warning"), comments, warnings)
if advice:
comments = add_list_of_advices (_ ("Tips"), comments, tips)
raises ValidationError (comments)

def get_help_text (auto):
expectations = _ ("we wait")
if self.password_minimal_strengh == 0:
expectations + = "{}". format (
_ ("nothing: you can use the password you want.")
)
back expectations
expectations + = "{}". format (_ ("a password that can not be guessed"))
hardness = {
1: _ ("by your family or friends."),
2: _ ("by online attackers."),
3: _ ("without access to our database."),
4: _ ("without a dedicated team and access to our database."),
}
expectations + = "{}". format (hardness.get (self.password_minimal_strengh))
returns the format "{} {} {} {}". (
_ ("There is no specific rule for a good password,"),
_ ("however, if your password is too easy to guess"),
_ ("we will tell you how to make a better one."),
expectations
)

The translation is done here:

import registration

of django.utils.translation import ugettext_lazy as _

LOGGER = logging.getLogger (__ file__)


def translate_zxcvbn_text (text):
"" "This PR would make it cleaner, but it will also be very slow
be integrated with python-zxcvbn and we want it to work now:
https://github.com/dropbox/zxcvbn/pull/124 "" "
i18n = {
"Use a few words, avoid common expressions": _ (
"Use a few words, avoid common expressions"
)
"No need for symbols, numbers, or uppercase letters": _ (
"No need for symbols, numbers or capital letters"
)
"Add another word or two.Rare words are better.": _ (
"Add another word or two, unusual words are better."
)
"The rows of straight keys are easy to guess": _ (
"The rows of straight keys are easy to guess"
)
"Short keyboard models are easy to guess": _ (
"Short keyboard patterns are easy to guess"
)
"Use a longer keyboard model with more turns": _ (
"Use a longer keyboard model with more turns"
)
& # 39; Repetitions like "aaa" are easy to guess:
"Repetitions like" aaa "are easy to guess"
)
& # 39; Repetitions like "abcabcabc" are only slightly more difficult to guess than "abc": _ (
Repetitions like "abcabcabc" are only slightly more difficult to guess than "abc" & # 39;
)
"Avoid words and repeated characters": _ ("Avoid words and repeated characters"),
& # 39; Sequences like "abc" or "6543" are easy to guess ": _ (
"Sequences like" abc "or" 6543 "are easy to guess"
)
"Avoid sequences": _ ("Avoid sequences"),
"The last years are easy to guess": _ ("The last years are easy to guess"),
"Avoid the last years": _ ("Avoid the last years"),
"Avoid the years associated with you": _ (
"Avoid the years associated with you"
)
"Dates are often easy to guess": _ ("Dates are often easy to guess"),
"Avoid dates and years associated with you": _ (
"Avoid dates and years associated with you"
)
"This is a common password of the top 10": _ ("This is a common password of the top 10"),
"This is a common password of the top 100": _ ("This is a common password of the top 100"),
"This is a very common password": _ ("This is a very common password"),
"It looks like a commonly used password": _ (
"This is similar to a commonly used password"
)
"A word in itself is easy to guess": _ ("A word in itself is easy to guess"),
"Names and names by themselves are easy to guess": _ (
"Names and names by themselves are easy to guess"
)
"Common names and first names are easy to guess": _ (
"The names and surnames are easy to guess"
)
"Capitalization does not help much": _ (
"Capitalization does not help much"
)
"The upper case is almost as easy to guess as the lower case": _ (
"All capital is almost as easy to guess as everything in lowercase"
)
"Inverse words are not harder to guess": _ (
"Inverse words are not harder to guess"
)
"Predictable substitutions like" @ "instead of" a "do not help much": _ (
"Predictable substitutions like" @ "instead of" a "do not help much"
)
}
translate_text = i18n.get (text)
if translate_text is None:
# zxcvbn is inconsistent, sometimes there is a dot, sometimes not
translate_text = i18n.get (text[:-1])
if translate_text is None:
LOGGER.warning (
"No translations for"% s "or"% s ", update the generatei18ndict command.",
text,
text[:-1],
)
return text
return translate_text


def translate_zxcvbn_time_estimate (text):
def replace_dict (text, times):
for original, translated into times.items ():
text = text.replace (original, str (translated))
return text

if text == "less than one second":
return _ ("less than one second")
text = text.replace ("centuries", str (_ ("centuries")))
plural_times = {
"seconds": _ ("seconds"),
"minutes": _ ("minutes"),
"hours": _ ("hours"),
"days": _ ("days"),
"month": _ ("month"),
"years": _ ("years"),
}
times = {
"second": _ ("second"),
"minute": _ ("minute"),
"hour": _ ("hour"),
"day": _ ("day"),
"month": _ ("month"),
"year": _ ("year"),
}
# Plural first to avoid replacing "hours" with _ ("hour") + s
# Add a & # 39; s & # 39; does not mean plural in all languages
text = replace_dict (text, plural_times)
text = replace_dict (text, times)
return text

This part of the code is mainly generated by the following management command (made in case zxcvbn add a string or delete a string to make it easier to create a new translation):

# - * - coding: utf-8 - * -

from django.core.management.base import BaseCommand


Command class (BaseCommand):

help = "Generate what i18n says for translate_zxcvbn_text"

def handle (self, * args, ** options):
existings_messages = [
            "Use a few words, avoid common phrases",
            "No need for symbols, digits, or uppercase letters",
            "Add another word or two. Uncommon words are better.",
            "Straight rows of keys are easy to guess",
            "Short keyboard patterns are easy to guess",
            "Use a longer keyboard pattern with more turns",
            'Repeats like "aaa" are easy to guess',
            'Repeats like "abcabcabc" are only slightly harder to guess than "abc"',
            "Avoid repeated words and characters",
            'Sequences like "abc" or "6543" are easy to guess',
            "Avoid sequences",
            "Recent years are easy to guess",
            "Avoid recent years",
            "Avoid years that are associated with you",
            "Dates are often easy to guess",
            "Avoid dates and years that are associated with you",
            "This is a top-10 common password",
            "This is a top-100 common password",
            "This is a very common password",
            "This is similar to a commonly used password",
            "A word by itself is easy to guess",
            "Names and surnames by themselves are easy to guess",
            "Common names and surnames are easy to guess",
            "Capitalization doesn't help very much",
            "All-uppercase is almost as easy to guess as all-lowercase",
            "Reversed words aren't much harder to guess",
            "Predictable substitutions like '@' instead of 'a' don't help very much",
        ]
        msg = "i18n = {"
for the message in existings_messages:
message = message.replace ("& # 39;", "\ & # 39;")
msg + = f "{message}" _ ("message"), "
msg + = "}"
msg + = "Please copy and paste the following in translate_zxcvbn_text,"
msg + = "Then use 'python manage.py makemessages'."
print (msg)

That's all the code, everything else consists of tests, documentation or packaging.

Thank you in advance for your remarks or advice!

python – How to find and watch a specific pixel in a tiff file?

I have a TIFF file and I was wondering how to find the specific pixel value and read the color. This is a grayscale photo, but the RGB format would be very useful (R, B, G). I want to read several pixels on this tiff file. I know the exact location of the pixel I want, but I do not know how to get the value so I can find the color.

The general goal is to find the color of a given pixel, not to find the value of the pixel.

python – regex version of strip () – Ch. 7 Automate the boring stuff

Here is a practical exercise – Regex version of gang() $ – $

Write a function that takes a string and does the same thing as the
gang() chain method. If no other argument has gone beyond the
string to strip, the spacing characters will be removed from the
beginning and end of the chain. Otherwise, the specified characters
in the second argument of the function will be removed from the
chain.

I wrote the following code. Is there a better way to write it? All comments are highly appreciated.

import re

def regex_strip (s, chars = None):

if characters == none:
strip_left = re.compile (r & # 39; ^  s *)
strip_right = re.compile (r  s * $ & # 39;)

s = re.sub (strip_left, "", s)
s = re.sub (strip_right, "", s)
other:
strip_left = re.compile (r & # 39; ^[' + re.escape(chars) + r']* & # 39;)
strip_right = re.compile (r & # 39;[' + re.escape(chars) + r']* $ & # 39;)
s = re.sub (strip_left, "", s)
s = re.sub (strip_right, "", s)
results

Here is an example of an exit –

s = & # 39; * alphabetatheta * 4453 + - & # 39;
print (regex_strip (s, & # 39 ;. + - *))

>>> alphabetatheta * 4453   

python – Implementation of a custom algorithm for automatic localization in one of the cloud computing platoforms

I am particularly new in cloud computing, naked me please.
Suppose I want to implement proactive and responsive automatic scaling algorithms. How can I implement this in some cloud computing platforms. I would just like to compare my results with existing algorithms that are already used for autoscaling.

I've done some research to do it on Kubernetes but I really did not find anything useful. I also came across Cloudsim but the documentation is not really good and so I have trouble understanding all the classes correctly. I would really appreciate if anyone could give me a length of time because I do not know where to start.

python – explicit lyrics

Split line in words using words = line.split ("") will only divide the line on the spaces. If two words are separated by a tab character or other white space character other than a space, the division will not take place at this point, which could confuse your explicit verifier.

Using words = line.split () would be divided into spaces, tab characters, and any other blank space characters.

You may also want to study the division using the crossword regular expression b, which would treat non-word characters as breaking points, so that a line containing an explicit word immediately followed by a comma (such as "explicit,") or a period, a semicolon, etc. will not sneak through the filter.


                                                for explicit_word in explicit_words:
if word == explicitword:
returns False

Python has a great integrated search. Instead of explicitly writing a loop on all explicit words, you can simply ask Python to tell you if a word is in the list of explicit words:

                                                if word in explicit_words:
returns False

Or better, use a together() explicit words, and the in the operation falls from $ O (n) $ at $ O (1) $ temporal complexity:

explicit_words = {
"explicit", "bad", "ugly", "offensive", "words"
}

# ...

if word in explicit_words:
returns False

We have a little improved things, but we still have an explicit loop (pun) on the list of words of a line. We can use the all() method, and an understanding of the list, for Python to loop for us, which should be faster.

                for the line in the song:
words = line.split ()
if applicable (word in explicit_words for word in words):
returns False

Yes explicit word results True for one of the word in the list words, the all() method will "short-circuit" and return immediately True without examining the remaining elements in words.


Yes "explicit" is a bad word, and the lyrics of the song contains "Explicit" or "EXPLICIT", you would not want to mark the song as "CLEAN", right? Maybe you want word.lower () in explicit_words?


Resulting method:

explicit_words = {
"explicit", "bad", "ugly", "offensive", "words"
}

def isClean (song_path):
with open (song_path) as song:
for the line in the song:
words = line.split ()
where applicable (word.lower () in explicit_words for a word in words):
returns False
returns True

python – Class to generate an invoice pdf

I am learning how to work with OOP design templates and so I challenged myself to create a way to generate a pdf invoice from certain information entered. This is what I have done so far and I would like to have an overview of my approach and my design.

Facture.py

import fpdf
since datetime import datetime

Creator class:
def __init __ (self, first name, last name, e-mail, phone number, address, city, country):
self.first_name = first name
self.last_name = last_name
self.email = email
self.phone_num = phone_num
self.address = address
self.city = city
country = country

Class Organization:
def __init __ (name, address, city, country):
self.name = name
self.address = address
self.city = city
country = country

BankAccountDetail class:
def __init __ (self, account_name, account_number, currency, bank name, branch, branch address):
self.account_name = account_name
self.account_num = account_num
self.currency = currency
self.bank_name = name of the bank
self.branch = branch
self.branch_addr = branch_addr

class project:

def __init __ (auto, name, description, amount):
self.name = name
self.description = description
self.amount = amount

class invoice:
& # 39; & # 39; & # 39;
Billing class used to model an invoice object composed of
1. Creative object
2. Object of organization
3. Purpose of the project
4. BankDetail Object
& # 39; & # 39; & # 39;

def __init __ (self, invoice_num, creator, organization, project, bankaccountdetail):
self.invoice_num = invoice_num
self.creator = creator
auto.organization = organization
self.project = project
self.bankaccountdetail = bankaccountdetail

Class file:
def __init __ (self, file name, font size, line height, orientation):
self.filename = filename
self.font_size = font_size
self.line_height = line_height
auto.orientation = orientation


PdfInvoice class (Invoice):
& # 39; & # 39; & # 39;
Inherits Parent Invoice class and has additional functionality
1. File object: used to specify some basic details about the file
& # 39; & # 39; & # 39;
def __init __ (self, invoice_num, creator, organization, project, bankaccountdetail, file):
super () .__ init __ (invoice_num, creator, organization, project, bankaccountdetail)
self.file = file

def generate_pdf (auto):
dt = datetime.now ()
date = dt.date ()
pdf = fpdf.FPDF (format = self.file.orientation)
pdf.add_page ()
pdf.set_font ("Arial", size = self.file.font_size)
pdf.write (self.file.line_height, "Invoice Number #")
pdf.write (self.file.line_height, self.invoice_num)
pdf.ln ()
pdf.write (self.file.line_height, "Billing Date #")
pdf.write (self.file.line_height, str (date))
pdf.ln ()
pdf.write (self.file.line_height, "Billed by #")
pdf.write (self.file.line_height, "{} {}". format (self.creator.first_name, self.creator.last_name))
pdf.ln ()
pdf.write (self.file.line_height, "Address #")
pdf.write (self.file.line_height, self.creator.address)
pdf.ln ()
pdf.write (self.file.line_height, "City #")
pdf.write (self.file.line_height, self.creator.city)
pdf.ln ()
pdf.write (self.file.line_height, "Country #")
pdf.write (self.file.line_height, self.creator.country)
pdf.ln ()
pdf.write (self.file.line_height, "Email #")
pdf.write (self.file.line_height, self.creator.email)
pdf.ln ()
pdf.write (self.file.line_height, "phone number #")
pdf.write (self.file.line_height, self.creator.phone_num)
pdf.ln ()
pdf.write (self.file.line_height, "Billed at #")
pdf.ln ()
pdf.write (self.file.line_height, "Name of the organization #")
pdf.write (self.file.line_height, self.organization.name)
pdf.ln ()
pdf.write (self.file.line_height, "Address of the organization")
pdf.write (self.file.line_height, self.organization.address)
pdf.ln ()
pdf.write (self.file.line_height, "City of Organization")
pdf.write (self.file.line_height, self.organization.city)
pdf.ln ()
pdf.write (self.file.line_height, "Country of Organization")
pdf.write (self.file.line_height, self.organization.country)
pdf.ln ()
pdf.write (self.file.line_height, "Comments #")
pdf.write (self.file.line_height, self.project.description)
pdf.ln ()
pdf.write (self.file.line_height, "Amount #")
pdf.write (self.file.line_height, str (self.project.amount))
pdf.ln ()
pdf.write (self.file.line_height, 'account details')
pdf.ln ()
pdf.write (& # 39; Account Name # & # 39;)
pdf.write (self.file.line_height, self.bankaccountdetail.account_name)
pdf.ln ()
pdf.write (& # 39; account number # & # 39;)
pdf.write (self.file.line_height, self.bankaccountdetail.account_num)
pdf.ln ()
pdf.write (& # 39; Account currency # & # 39;)
pdf.write (self.file.line_height, self.bankaccountdetail.currency)
pdf.ln ()
pdf.write (& # 39; Bank Name # & # 39;)
pdf.write (self.file.line_height, self.bankaccountdetail.bank_name)
pdf.ln ()
pdf.write (& # 39; Branch Address #)
pdf.write (self.file.line_height, self.bankaccountdetail.branch_addr)
pdf.ln ()
pdf.output (self.file.filename)

creator = Creator ("Test", "User", "test@gmail.com", #######,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
& # 39; 099006789 & # 39 ;, & quot; Joans Apartment, 123 Road Test & # 39 ;, & quot; Nairobi & # 39 ;, & quot; Kenya & # 39;)

organization = organization ("Test Organ", "Kilimani Road", "Nairobi", "Kenya")

bank_detail = BankAccountDetail ("Test User", "999999678", "KES")
& # 39; Test Bank & # 39 ;, & quot; Kenya & # 39 ;, & # 39; BRANCH Way & ABC Place & # 39;)

file = File ("Invoice.pdf", 12,5, "letter")

project = Project ("E-Commerce Site", "Worked on e-commerce site", 10.900)

pdf_inv = PdfInvoice (& # 39; 1393939 & # 39 ;, creator, organization, project, bank_detail, file)
pdf_inv.generate_pdf ()

UML diagram

Python – Whitens black outlines around an asymmetric image

I have this picture:

enter the description of the image here

I want to whiten the black contours (borders) without affecting the content of the image.
Here is the code that I used:

import cv2
import numpy as np
import shapely.geometry as shageo


img = cv2.imread (& # 39; filename.jpg & # 39;)

# retrieve the gray image and perform a binary
gray = cv2.cvtColor (img, cv2.COLOR_RGB2GRAY)
Grey[Grey[gray[gris[gray< 20] = 0
gray[gray > 0]= 255

# get the biggest limit of the binary image to locate the target
outline, _ = cv2.findContours (gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
rect = cv2.minAreaRect (outlines[0])
box = cv2.boxPoints (rect)
box = np.int0 (box)

poly = shageo.Polygon (box)
h, w = img.shape[:2]
ind = np.zeros ((h, w), np.bool)

# check whether the point is inside the target or not
for i in the beach (h):
for j in the range (w):
p = shageo.Point (j, i)
otherwise p.within (poly):
Indiana[i, j] = True

# whiten the outside points
img[ind] = (255, 255, 255)
cv2.imwrite (& # 39; result.jpg & # 39 ;, img)

Here is the result:
enter the description of the image here

As you can see, the code works well, but it is very slow because of the for loops.

Any suggestions to avoid loops for or to make them faster?

How to use Realsense in python, function save_single_frameset

I'm using the Realsense python wrapper with the D435 camera

trying to apply the save_single_frameset to my project

I'm running with Python 2.7 and the latest realsense library

I'm using code like here

saver = rs.save_single_frameset ()
frames = pipeline.wait_for_frames ()
saver.process (frames)

it's defined as a filter and it records each record in a separate bag, but there's a problem

the frameset has no depth data,

they can be seen in the realsense viewer, but in the viewer he always shows 0 meter away

I also asked on github but it was closed without explanation
https://github.com/IntelRealSense/librealsense/issues/4020

my data here
https://drive.google.com/drive/folders/1gwyfJPE9nwYzyF-xGc4gqyrfuHttErim

a version using the rs.recorder code

with recorder

and saving the single-frame version

save a single set of frames

because here seems similar, the problem is to get depth data