ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2021-09-24截图 照片二分类及判断截图原始性的一种方法

2021-09-24 19:06:01  阅读:138  来源: 互联网

标签:24 截图 xa2 09 xff x8a x01E x00 image


import os


 

''' 

    Explainations:

        root: path of the image folder

        image_list: path of each image

        images: name of each image

        dirs: =images

        target_info_seg: information segments that always occur in screenshots but rarely occur in photos

        pri_iden_mark: primitiveness identification marks, which can be used to judge whether a screenshot is original or not

        process_time: record the number of times the image is processed

    If you want to test on your own data, just change the root is fine.

    

'''

root = './MyData/Screenshot-wechat-unprocessed/'

image_list = []

images = []

dirs = os.listdir(root)

target_info_seg = [

    b'(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a(\xa0\x02\x8a',

    b'\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P\x01E\x14P',

    b'(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n(\xa2\x80\n',

    b'(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00(\xa2\x8a\x00',

    b'\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14\x00QE\x14',

    b'\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@\x05\x14Q@',

    b'\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00\x14QE\x00',

    b'(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a(\x00\xa2\x8a',

    b'$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$\x92R\x92I$\x94\xa4\x92I%)$\x92IJI$'

]

pri_iden_mark = [

    b'\xff\xe0', b'\xff\xe1', b'\xff\xe2', b'\xff\xe3', 

    b'\xff\xe4', b'\xff\xe5', b'\xff\xe6', b'\xff\xe7', 

    b'\xff\xe8', b'\xff\xe9', b'\xff\xea', b'\xff\xeb', 

    b'\xff\xec', b'\xff\xed', b'\xff\xee', b'\xff\xef' 

]

process_time = 0


 

''' create the image name list and the image path list '''

for image in dirs:

    images.append(image)

    tmp = os.path.join(root+image)

    image_list.append(tmp)


 

''' read the binary data of each image '''

for i in range(len(image_list)):

    image_path = image_list[i]

    with open(image_path, "rb") as file:

        jpg_bin = file.read()


 

        ''' print module '''

        print('\033[0;31;40mNo:\033[0m', i + 1, '\033[0;31;40m---\033[0m', 

                images[i], '\n')


 

        ''' judgement module1: screenshot/photo '''

        ''' determine whether every segment is contained in the binary data  '''

        for j in range(len(target_info_seg)):

            if jpg_bin.find(target_info_seg[j]) == -1:

                flag = 'p'

                break

            elif j == len(target_info_seg)-2:

                # print('Found segment', j, 'at position', jpg_bin.find(target_info_seg[j]))

                flag = 's'

                break     

        ''' Photoshop-processed target information section judgement '''

        if jpg_bin.find(target_info_seg[8]) != -1: 

            flag = 's'

                   

        ''' print result: photo/screenshot '''

        if flag == 's':

            print('\033[0;31;36mScreenshot\033[0m')

        elif flag == 'p':

            print('\033[0;31;36mPhoto\033[0m\n')

        

        ''' judgement module2: processed/unprocessed '''

        if flag == 's':

            for k in range(len(pri_iden_mark)):

                if jpg_bin.find(pri_iden_mark[k]) != -1:

                    process_time += 1

                if process_time > 1:

                    print('\033[0;31;40mImprimitive\033[0m\n')

                    break

                elif k == len(pri_iden_mark)-1:

                    print('Primitive\n')

                    break

    process_time = 0


 

标签:24,截图,xa2,09,xff,x8a,x01E,x00,image
来源: https://blog.csdn.net/m0_60313088/article/details/120461223

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有