SoFunction
Updated on 2024-11-17

python randomly intercepts an image of any size on a single image

python randomly intercepts an image of any size on a single image

Updated January 24, 2019 14:49:36 by Lw_Akeman
Today I'm going to share a python randomly on an image to intercept any size of the picture method, has a good reference value, I hope to help you. Together follow the editor over to see it

As shown below:

'''
Randomized Generation of Negative Samples in Machine Learning
'''
 
import cv2
import random
 
#Read the picture
img=('')
 
#h, w is the size of the image you want to capture
h=80
w=80
 
count=1
while 1:
    # Randomize x,y. This is a pixel-by-pixel range generation.
   y = (1, 890)
  x = (1, 1480)
  # Random screenshots
   cropImg = img[(y):(y + h), (x):(x + w)]
  ('pic/' + str(count) + '.png', cropImg)
  count+=1
 
  if count==2500:
    break
 

Above this python randomly on an image to intercept any size of the picture is all I share with you, I hope to give you a reference, and I hope you support me more.

  • python
  • interception
  • photograph

Related articles

  • Python3.9.0 a1 install pygame error resolution process (summary)

    This article introduces the Python3.9.0 a1 installation pygame error resolution of the whole process (summary), the text through the sample code is very detailed, for everyone's learning or work has a certain reference and learning value, the need for friends below with the editorial to learn together!
    2021-02-02
  • Implementation of Parameter Packing and Unpacking in Python

    In Python, packing and unpacking parameters is a way to operate, you can pack multiple parameters into a tuple or dictionary, or you can unpack a tuple or dictionary into multiple parameters, this article will introduce how to use the
    2023-09-09
  • A summary of five Python implementations for solving for the greatest common divisor

    Finding the greatest common divisor is a relatively common type of exercise, this article will provide you with five more common algorithms, are implemented in the Python language, interested partners can understand the
    2022-07-07
  • django tutorial how to teach yourself

    In this content, I have organized a tutorial on django learning process, want to self-study friends can read.
    2020-07-07
  • python calls to the saf automation framework

    Today, I'd like to share a python call to the STAF automation framework, with good reference value, I hope to help you. Together follow the editor over to see it
    2018-12-12
  • Summary of influx+grafana custom python collection data and some pitfalls

    Some of the data type is not correct will lead to no datapoint error, it is really crazy, this article is to summarize the collection of data kind of some of the pit, I hope you can benefit from it!
    2018-09-09
  • How to use FFmpeg to compress video files losslessly

    FFmpeg is the industry's famous open-source image video processing program, in many video editing software, image processing software, are used in the FFmpeg, as well as such as OBS guide software inside the use of the FFmpeg, FFmpeg is very powerful, not only video compression, this article describes the use of FFmpeg to lossless compression of video files, the operation of the method! This article describes how to use FFmpeg to lossless compression of video files, interested friends to look at it together!
    2023-12-12
  • Explaining Containers in Python Collections

    This article mainly introduces the Python container collections of relevant information to help you better understand and learn python, interested parties can learn about the
    2020-08-08
  • Python set

    set is an unordered and non-repeating set of elements. This article mainly introduces the Python set of commonly used functions, need friends can refer to the following
    2017-11-11
  • Programmer's Eve with 30 lines of code to make Python incarnation of the confession of God

    Turning to our traditional Chinese Valentine's Day Tanabata, today I will take you to appreciate the way to use Python confession, interested friends to follow the editor together to see it!
    2019-08-08

Latest Comments