Created
          July 18, 2021 18:21 
        
      - 
      
 - 
        
Save villares/7bef22870e74957aaff5144d899b336f to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | """ | |
| Example of Video Capture on Processing Python Mode | |
| """ | |
| add_library('video') | |
| add_library('pdf') | |
| cell_size = 16 # cell size | |
| save_pdf = False | |
| def setup(): | |
| global cols, rows, video | |
| size(640, 480) | |
| noStroke() | |
| smooth() | |
| rectMode(CENTER) | |
| cols = int(width / cell_size) | |
| rows = int(height / cell_size) | |
| video = Capture(this, width, height) | |
| video.start() | |
| background(0) | |
| def draw(): | |
| global save_pdf | |
| if video.available(): | |
| if save_pdf: # if you press 'p' | |
| fill(0) | |
| rect(0, 0, width, height) | |
| beginRecord(PDF, "Image.pdf") | |
| background(0) | |
| video.read() | |
| video.loadPixels() # makes video.pixels available | |
| for i in range(cols): | |
| for j in range(rows): | |
| x = i * cell_size | |
| y = j * cell_size | |
| loc = x + y * video.width | |
| px_color = video.pixels[loc] | |
| # px_color = video.get(x, y) # slower but the same as previous line | |
| tam = map(brightness(px_color), 0, 255, 0, cell_size - 1) | |
| sat = saturation(px_color) | |
| colorMode(HSB) | |
| fill(sat, 255, 255) | |
| rect(x + cell_size / 2, y + cell_size / 2, tam, tam) | |
| if (save_pdf): | |
| endRecord() | |
| println('gravado arquivo imagem.pdf') | |
| save_pdf = False | |
| def keyPressed(self): | |
| global save_pdf | |
| if key == 'p': | |
| save_pdf = True | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment