title: How to run two python3 file with both file using the same Raspberry Pi Camera
body: <p>I have two python3 file</p>
  <p>#1 Facemask recognition (Deep Learning)</p>
  <p>#2 QR Code scanner (Machine Learning)</p>
  <p>Im using Raspberry Pi 3 B+ &amp; 8 MP single Pi Cam</p>
  <p>Both program does not have any connection, however I need to run both at the same time to detect someone who mask or not AND to scan QR code of user</p>
  <p>The problem is I found conflict on pi camera because I only use one pi camera for two different program. Plus, facemask using videostream while QR Scan using videocaptures.</p>
  <p>Hope someone can help me on pi camera conflict with two python3 file that using it.</p>
  <p>Below is my code:</p>
  <p>#1 Facemask Recognition based on Github</p>
  <p><a href="https://github.com/manish-1305/facemask_detection/blob/73f37f724b519731eec7d46cb4a23482147db24b/detect.py" rel="nofollow noreferrer">https://github.com/manish-1305/facemask_detection/blob/73f37f724b519731eec7d46cb4a23482147db24b/detect.py</a></p>
  <p>#2 QR Code Scanner</p>
  <pre><code>import cv2
  import re
  from time import time
  import datetime
  import board
  
  
  cap = cv2.VideoCapture(0)
  detector = cv2.QRCodeDetector()
  
  def sw1Pressed():
      global sw1Press
      sw1Press = True
  
  sw1.when_pressed = sw1Pressed
  sw1Press = False
  
  
  print(&quot;Press SW1 to scan.&quot;)
  
  
  while True:
      if sw1Press == True:
          led.toggle()
          
          _, img = cap.read()
          data, bbox, _ = detector.detectAndDecode(img)
          
          if bbox is not None:
              for i in range(len(bbox)):
                  cv2.line(img, tuple(bbox[i][0]), tuple(bbox[(i+1) % len(bbox)][0]), color=(255,
                           0, 0), thickness=2)
                  
              cv2.putText(img, data, (int(bbox[0][0][0]), int(bbox[0][0][1]) - 10), cv2.FONT_HERSHEY_SIMPLEX,
                          0.5, (0, 255, 0), 2)
              
              if data:
                  sw1Press = False
                  
                  data = data.split(&quot;,&quot;)
                  print(&quot;ID: &quot; + data[0])
                  print(&quot;NAME: &quot; + data[1])
                 
                  print()
                  
                  userScanned = False
                  with open('XXX.csv') as csvfile:
                      reader = csv.DictReader(csvfile)
                      for row in reader:
                          if row[&quot;ID&quot;] == data[0]:
                              buzzer.beep(0.1, 0.1, 1)
                              userScanned = True
                      
                  if userScanned == False:
                      buzzer.beep(0.1, 0.1, 2)
                      with open('XXX.csv', 'a') as csvfile:
                          fieldNames = ['ID', 'NAME']
                          
                          writer = csv.DictWriter(csvfile, fieldnames=fieldNames)
                          writer.writerow({'ID': data[0], 'NAME': data[1]})
                          
                  currentTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
                  
                  print(&quot;Date &amp; Time: {}&quot;.format(currentTime))
                  print()
                  
                  data = {
                  'ID' : data[0],
                  'NAME' : data[1],
                  
                  'TIME' : currentTime,
                 
                  }
                  
          cv2.imshow(&quot;code detector&quot;, img)
      
      else:
          cap.read()
          cv2.destroyAllWindows()
      
      
      if cv2.waitKey(1) == ord(&quot;q&quot;):
          break
  
  led.off()
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>