Extracting watermark from a video using Python The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Extracting Pixels From Image Byte[]Load images, manipulate DOM, store/retrieve data using localStorageExtracting information from filesExtracting lines from a bytearrayExtracting keywords from 3 billion CSV recordsExtracting original values from cumulative sum valuesConverting images to greyscale using JuicyPixelPython Steganographer using PILGenerate video thumbnailExtracting face features from selfies faster

How to test the equality of two Pearson correlation coefficients computed from the same sample?

Create an outline of font

"... to apply for a visa" or "... and applied for a visa"?

Relations between two reciprocal partial derivatives?

A pet rabbit called Belle

He got a vote 80% that of Emmanuel Macron’s

Typeface like Times New Roman but with "tied" percent sign

Is every episode of "Where are my Pants?" identical?

What can I do if neighbor is blocking my solar panels intentionally?

Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?

Did God make two great lights or did He make the great light two?

Segmentation fault output is suppressed when piping stdin into a function. Why?

Mortgage adviser recommends a longer term than necessary combined with overpayments

Does the AirPods case need to be around while listening via an iOS Device?

How did passengers keep warm on sail ships?

Can a 1st-level character have an ability score above 18?

University's motivation for having tenure-track positions

Grover's algorithm - DES circuit as oracle?

First use of “packing” as in carrying a gun

Who or what is the being for whom Being is a question for Heidegger?

Hopping to infinity along a string of digits

Would an alien lifeform be able to achieve space travel if lacking in vision?

Do working physicists consider Newtonian mechanics to be "falsified"?

Would it be possible to rearrange a dragon's flight muscle to somewhat circumvent the square-cube law?



Extracting watermark from a video using Python



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Extracting Pixels From Image Byte[]Load images, manipulate DOM, store/retrieve data using localStorageExtracting information from filesExtracting lines from a bytearrayExtracting keywords from 3 billion CSV recordsExtracting original values from cumulative sum valuesConverting images to greyscale using JuicyPixelPython Steganographer using PILGenerate video thumbnailExtracting face features from selfies faster



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2












$begingroup$


I'm extracting a few frames from a video:



  • Comparing the similarity or equality of pixel color (from first two images)


  • Saving to a new image


  • Comparing the new image (conjunction of first two images) and the next image, etc.


Can you review my codes for efficiency and best coding practices?



Code



import sys
import os
import numpy as np
from PIL import Image, ImageDraw


def main(obr1,obr2):
img1= Image.open("%s" %(obr1))
img2= Image.open("%s" %(obr2))
im1 = img1.convert("RGBA")
im2 = img2.convert("RGBA")
pix1 = im1.load()
pix2 = im2.load()
im = Image.new("RGBA", (im1.width, im1.height), (0, 0, 0, 0))
draw = ImageDraw.Draw(im)
x = 0
y = 0
while y != im1.height-1 or x != im1.width-1:
if pix1[x,y] == pix2[x,y]:
draw.point((x,y),fill=pix1[x,y])
else:
p1 = np.array([(pix1[x,y][0]),(pix1[x,y][1]),(pix1[x,y][2])])
p2 = np.array([(pix2[x,y][0]),(pix1[x,y][1]),(pix1[x,y][2])])
squared_dist = np.sum(p1**2 + p2**2, axis=0)
dist = np.sqrt(squared_dist)
if dist < 200 and pix1[x,y] !=(0,0,0,0) and pix2[x,y] != (0,0,0,0):
color = (round(pix1[x,y][0]+pix2[x,y][0]/2), round(pix1[x,y][1]+pix2[x,y][1]/2), round(pix1[x,y][2]+pix2[x,y][2]/2), round(pix1[x,y][3]+pix2[x,y][3]/2))
#color=pix1[x,y]
draw.point((x,y),fill=color)
else:
draw.point((x,y),fill=(0,0,0,0))
if x == im1.width-1:
x=0
y=y+1
else:
x=x+1
im.save('test%s.png' %(z), 'PNG')
print("Zapisano obraz test%s.png" %(z))





imglist = sys.argv[1:]
z=0
while imglist != []:
exists = os.path.isfile("./test%s.png" % (z-1))
if exists:
obr1="test%s.png" % (z-1)
obr2=imglist.pop()
print("Porównywanie obraza %s i %s" % (obr1,obr2))
main(obr1,obr2)
print("Analiza skończona")
z=z+1
else:
obr1=imglist.pop()
obr2=imglist.pop()
print("Porównywanie obraza %s i %s" % (obr1,obr2))
main(obr1,obr2)
print("Analiza skończona")
z=z+1









share|improve this question









New contributor




Fejor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$


















    2












    $begingroup$


    I'm extracting a few frames from a video:



    • Comparing the similarity or equality of pixel color (from first two images)


    • Saving to a new image


    • Comparing the new image (conjunction of first two images) and the next image, etc.


    Can you review my codes for efficiency and best coding practices?



    Code



    import sys
    import os
    import numpy as np
    from PIL import Image, ImageDraw


    def main(obr1,obr2):
    img1= Image.open("%s" %(obr1))
    img2= Image.open("%s" %(obr2))
    im1 = img1.convert("RGBA")
    im2 = img2.convert("RGBA")
    pix1 = im1.load()
    pix2 = im2.load()
    im = Image.new("RGBA", (im1.width, im1.height), (0, 0, 0, 0))
    draw = ImageDraw.Draw(im)
    x = 0
    y = 0
    while y != im1.height-1 or x != im1.width-1:
    if pix1[x,y] == pix2[x,y]:
    draw.point((x,y),fill=pix1[x,y])
    else:
    p1 = np.array([(pix1[x,y][0]),(pix1[x,y][1]),(pix1[x,y][2])])
    p2 = np.array([(pix2[x,y][0]),(pix1[x,y][1]),(pix1[x,y][2])])
    squared_dist = np.sum(p1**2 + p2**2, axis=0)
    dist = np.sqrt(squared_dist)
    if dist < 200 and pix1[x,y] !=(0,0,0,0) and pix2[x,y] != (0,0,0,0):
    color = (round(pix1[x,y][0]+pix2[x,y][0]/2), round(pix1[x,y][1]+pix2[x,y][1]/2), round(pix1[x,y][2]+pix2[x,y][2]/2), round(pix1[x,y][3]+pix2[x,y][3]/2))
    #color=pix1[x,y]
    draw.point((x,y),fill=color)
    else:
    draw.point((x,y),fill=(0,0,0,0))
    if x == im1.width-1:
    x=0
    y=y+1
    else:
    x=x+1
    im.save('test%s.png' %(z), 'PNG')
    print("Zapisano obraz test%s.png" %(z))





    imglist = sys.argv[1:]
    z=0
    while imglist != []:
    exists = os.path.isfile("./test%s.png" % (z-1))
    if exists:
    obr1="test%s.png" % (z-1)
    obr2=imglist.pop()
    print("Porównywanie obraza %s i %s" % (obr1,obr2))
    main(obr1,obr2)
    print("Analiza skończona")
    z=z+1
    else:
    obr1=imglist.pop()
    obr2=imglist.pop()
    print("Porównywanie obraza %s i %s" % (obr1,obr2))
    main(obr1,obr2)
    print("Analiza skończona")
    z=z+1









    share|improve this question









    New contributor




    Fejor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$














      2












      2








      2





      $begingroup$


      I'm extracting a few frames from a video:



      • Comparing the similarity or equality of pixel color (from first two images)


      • Saving to a new image


      • Comparing the new image (conjunction of first two images) and the next image, etc.


      Can you review my codes for efficiency and best coding practices?



      Code



      import sys
      import os
      import numpy as np
      from PIL import Image, ImageDraw


      def main(obr1,obr2):
      img1= Image.open("%s" %(obr1))
      img2= Image.open("%s" %(obr2))
      im1 = img1.convert("RGBA")
      im2 = img2.convert("RGBA")
      pix1 = im1.load()
      pix2 = im2.load()
      im = Image.new("RGBA", (im1.width, im1.height), (0, 0, 0, 0))
      draw = ImageDraw.Draw(im)
      x = 0
      y = 0
      while y != im1.height-1 or x != im1.width-1:
      if pix1[x,y] == pix2[x,y]:
      draw.point((x,y),fill=pix1[x,y])
      else:
      p1 = np.array([(pix1[x,y][0]),(pix1[x,y][1]),(pix1[x,y][2])])
      p2 = np.array([(pix2[x,y][0]),(pix1[x,y][1]),(pix1[x,y][2])])
      squared_dist = np.sum(p1**2 + p2**2, axis=0)
      dist = np.sqrt(squared_dist)
      if dist < 200 and pix1[x,y] !=(0,0,0,0) and pix2[x,y] != (0,0,0,0):
      color = (round(pix1[x,y][0]+pix2[x,y][0]/2), round(pix1[x,y][1]+pix2[x,y][1]/2), round(pix1[x,y][2]+pix2[x,y][2]/2), round(pix1[x,y][3]+pix2[x,y][3]/2))
      #color=pix1[x,y]
      draw.point((x,y),fill=color)
      else:
      draw.point((x,y),fill=(0,0,0,0))
      if x == im1.width-1:
      x=0
      y=y+1
      else:
      x=x+1
      im.save('test%s.png' %(z), 'PNG')
      print("Zapisano obraz test%s.png" %(z))





      imglist = sys.argv[1:]
      z=0
      while imglist != []:
      exists = os.path.isfile("./test%s.png" % (z-1))
      if exists:
      obr1="test%s.png" % (z-1)
      obr2=imglist.pop()
      print("Porównywanie obraza %s i %s" % (obr1,obr2))
      main(obr1,obr2)
      print("Analiza skończona")
      z=z+1
      else:
      obr1=imglist.pop()
      obr2=imglist.pop()
      print("Porównywanie obraza %s i %s" % (obr1,obr2))
      main(obr1,obr2)
      print("Analiza skończona")
      z=z+1









      share|improve this question









      New contributor




      Fejor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I'm extracting a few frames from a video:



      • Comparing the similarity or equality of pixel color (from first two images)


      • Saving to a new image


      • Comparing the new image (conjunction of first two images) and the next image, etc.


      Can you review my codes for efficiency and best coding practices?



      Code



      import sys
      import os
      import numpy as np
      from PIL import Image, ImageDraw


      def main(obr1,obr2):
      img1= Image.open("%s" %(obr1))
      img2= Image.open("%s" %(obr2))
      im1 = img1.convert("RGBA")
      im2 = img2.convert("RGBA")
      pix1 = im1.load()
      pix2 = im2.load()
      im = Image.new("RGBA", (im1.width, im1.height), (0, 0, 0, 0))
      draw = ImageDraw.Draw(im)
      x = 0
      y = 0
      while y != im1.height-1 or x != im1.width-1:
      if pix1[x,y] == pix2[x,y]:
      draw.point((x,y),fill=pix1[x,y])
      else:
      p1 = np.array([(pix1[x,y][0]),(pix1[x,y][1]),(pix1[x,y][2])])
      p2 = np.array([(pix2[x,y][0]),(pix1[x,y][1]),(pix1[x,y][2])])
      squared_dist = np.sum(p1**2 + p2**2, axis=0)
      dist = np.sqrt(squared_dist)
      if dist < 200 and pix1[x,y] !=(0,0,0,0) and pix2[x,y] != (0,0,0,0):
      color = (round(pix1[x,y][0]+pix2[x,y][0]/2), round(pix1[x,y][1]+pix2[x,y][1]/2), round(pix1[x,y][2]+pix2[x,y][2]/2), round(pix1[x,y][3]+pix2[x,y][3]/2))
      #color=pix1[x,y]
      draw.point((x,y),fill=color)
      else:
      draw.point((x,y),fill=(0,0,0,0))
      if x == im1.width-1:
      x=0
      y=y+1
      else:
      x=x+1
      im.save('test%s.png' %(z), 'PNG')
      print("Zapisano obraz test%s.png" %(z))





      imglist = sys.argv[1:]
      z=0
      while imglist != []:
      exists = os.path.isfile("./test%s.png" % (z-1))
      if exists:
      obr1="test%s.png" % (z-1)
      obr2=imglist.pop()
      print("Porównywanie obraza %s i %s" % (obr1,obr2))
      main(obr1,obr2)
      print("Analiza skończona")
      z=z+1
      else:
      obr1=imglist.pop()
      obr2=imglist.pop()
      print("Porównywanie obraza %s i %s" % (obr1,obr2))
      main(obr1,obr2)
      print("Analiza skończona")
      z=z+1






      python performance beginner image






      share|improve this question









      New contributor




      Fejor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Fejor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 5 mins ago









      Emma

      2001215




      2001215






      New contributor




      Fejor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 hour ago









      FejorFejor

      112




      112




      New contributor




      Fejor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Fejor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Fejor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Fejor is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217413%2fextracting-watermark-from-a-video-using-python%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Fejor is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          Fejor is a new contributor. Be nice, and check out our Code of Conduct.












          Fejor is a new contributor. Be nice, and check out our Code of Conduct.











          Fejor is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217413%2fextracting-watermark-from-a-video-using-python%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

          Prove that NP is closed under karp reduction?Space(n) not closed under Karp reductions - what about NTime(n)?Class P is closed under rotation?Prove or disprove that $NL$ is closed under polynomial many-one reductions$mathbfNC_2$ is closed under log-space reductionOn Karp reductionwhen can I know if a class (complexity) is closed under reduction (cook/karp)Check if class $PSPACE$ is closed under polyonomially space reductionIs NPSPACE also closed under polynomial-time reduction and under log-space reduction?Prove PSPACE is closed under complement?Prove PSPACE is closed under union?

          Is my guitar’s action too high? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Strings too stiff on a recently purchased acoustic guitar | Cort AD880CEIs the action of my guitar really high?Μy little finger is too weak to play guitarWith guitar, how long should I give my fingers to strengthen / callous?When playing a fret the guitar sounds mutedPlaying (Barre) chords up the guitar neckI think my guitar strings are wound too tight and I can't play barre chordsF barre chord on an SG guitarHow to find to the right strings of a barre chord by feel?High action on higher fret on my steel acoustic guitar