@ -273,7 +273,7 @@ def create_vendor(cur, row, marketId):
recset = cur . fetchall ( )
recset = cur . fetchall ( )
imageId = recset [ 0 ] [ ' image_vendor ' ]
imageId = recset [ 0 ] [ ' image_vendor ' ]
if not is_same_image ( row [ 21 ] , recset [ 0 ] [ ' image_vendor ' ] ) ) :
if not is_same_image ( cur , row [ 21 ] , recset [ 0 ] [ ' image_vendor ' ] ) :
imageId = create_image ( cur , row [ 21 ] , row [ 23 ] )
imageId = create_image ( cur , row [ 21 ] , row [ 23 ] )
if ( str ( recset [ 0 ] [ ' rating_vendor ' ] ) != str ( row [ 2 ] if row [ 2 ] != ' -1 ' else None ) or # there was a change in the vendor information
if ( str ( recset [ 0 ] [ ' rating_vendor ' ] ) != str ( row [ 2 ] if row [ 2 ] != ' -1 ' else None ) or # there was a change in the vendor information
@ -362,7 +362,7 @@ def create_items(cur, row, marketId, vendorId):
recset = cur . fetchall ( )
recset = cur . fetchall ( )
imageId = recset [ 0 ] [ ' image_item ' ]
imageId = recset [ 0 ] [ ' image_item ' ]
if not is_same_image ( row [ 20 ] , recset [ 0 ] [ ' image_item ' ] ) ) :
if not is_same_image ( cur , row [ 20 ] , recset [ 0 ] [ ' image_item ' ] ) :
imageId = create_image ( cur , row [ 20 ] , row [ 23 ] )
imageId = create_image ( cur , row [ 20 ] , row [ 23 ] )
if ( str ( recset [ 0 ] [ ' vendor_id ' ] ) != str ( vendorId ) or
if ( str ( recset [ 0 ] [ ' vendor_id ' ] ) != str ( vendorId ) or
@ -389,7 +389,7 @@ def create_items(cur, row, marketId, vendorId):
sql = " Insert into items_history (item_id, version_item, market_id, vendor_id, name_item, description_item, cve_item, ms_item, category_item, " \
sql = " Insert into items_history (item_id, version_item, market_id, vendor_id, name_item, description_item, cve_item, ms_item, category_item, " \
" views_item, reviews_item, rating_item, dateadded_item, btc_item, usd_item, euro_item, quantitysold_item, " \
" views_item, reviews_item, rating_item, dateadded_item, btc_item, usd_item, euro_item, quantitysold_item, " \
" quantityleft_item, shippedfrom_item, shippedto_item, lastseen_item, image_item, href_item, dateinserted_item, " \
" quantityleft_item, shippedfrom_item, shippedto_item, image_item, href_item, lastseen _item, dateinserted_item, " \
" classification_item) Values ( %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , " \
" classification_item) Values ( %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , " \
" %s , %s , %s , %s , %s , %s ) "
" %s , %s , %s , %s , %s , %s ) "
@ -425,7 +425,7 @@ def create_items(cur, row, marketId, vendorId):
" rating_item = %(rating_item)s , dateadded_item = %(dateadded_item)s , btc_item = %(btc_item)s , " \
" rating_item = %(rating_item)s , dateadded_item = %(dateadded_item)s , btc_item = %(btc_item)s , " \
" usd_item = %(usd_item)s , euro_item = %(euro_item)s , quantitysold_item = %(quantitysold_item)s , " \
" usd_item = %(usd_item)s , euro_item = %(euro_item)s , quantitysold_item = %(quantitysold_item)s , " \
" quantityleft_item = %(quantityleft_item)s , shippedfrom_item = %(shippedfrom_item)s , shippedto_item = %(shippedto_item)s , " \
" quantityleft_item = %(quantityleft_item)s , shippedfrom_item = %(shippedfrom_item)s , shippedto_item = %(shippedto_item)s , " \
" image_item = %(image_item)s , lastseen_item = %(lastseen_item)s , dateinserted_item = %(dateinserted_item)s . " \
" image_item = %(image_item)s , lastseen_item = %(lastseen_item)s , dateinserted_item = %(dateinserted_item)s , " \
" classification_item = %(classification_item)s where item_id = %(itemId)s "
" classification_item = %(classification_item)s where item_id = %(itemId)s "
cur . execute ( sql , { ' vendor_id ' : vendorId ,
cur . execute ( sql , { ' vendor_id ' : vendorId ,
@ -460,15 +460,15 @@ def create_items(cur, row, marketId, vendorId):
return itemId
return itemId
def is_same_image ( newBase64Image , oldImageId ) :
def is_same_image ( cur , newBase64Image , oldImageId ) :
if newBase64Image == " -1 " and oldImageId == " -1 " :
if newBase64Image == " -1 " and str ( oldImageId ) == str ( None ) :
return True
return True
if newBase64Image == " -1 " : # and oldImageId != "-1"
if newBase64Image == " -1 " : # and str(oldImageId) != str(None)
return False
return False
if oldImageId == " -1 " : # and newBase64Image != "-1"
if str ( oldImageId ) == str ( None ) : # and newBase64Image != "-1"
return False
return False
sql = " select * from market_images where image_id = %(imageId)s "
sql = " select * from market_images where image_id = %(imageId)s "
@ -476,7 +476,7 @@ def is_same_image(newBase64Image, oldImageId):
recset = cur . fetchall ( )
recset = cur . fetchall ( )
decImage = decode_decrypt_image_in_base64 ( b ase64Image)
decImage = decode_decrypt_image_in_base64 ( newB ase64Image)
hash1 = generate_image_hash ( decImage )
hash1 = generate_image_hash ( decImage )
hash2 = recset [ 0 ] [ ' hash_image ' ]
hash2 = recset [ 0 ] [ ' hash_image ' ]
@ -484,19 +484,21 @@ def is_same_image(newBase64Image, oldImageId):
if hash1 == hash2 :
if hash1 == hash2 :
return True
return True
features1 = json . loads ( extract_hidden_layer_output ( dec_string ) )
features1 = json . loads ( extract_hidden_layer_output ( decImage ) )
features2 = json . loads ( recset [ 0 ] [ ' resnet50_image ' ] )
features2 = json . loads ( recset [ 0 ] [ ' resnet50_image ' ] )
similarity = 1 - distance . cosine ( features1 , features2 )
similarity = 1 - distance . cosine ( features1 , features2 )
return similarity < 0.8
return similarity > = 0.8
def create_image ( cur , base64Image , date ) :
def create_image ( cur , base64Image , date ) :
if base64Image == " -1 " :
if base64Image == " -1 " :
return None
return None
imageId = verifyImage ( base64Image )
decImage = decode_decrypt_image_in_base64 ( base64Image )
imageId = verifyImage ( cur , decImage )
if not imageId :
if not imageId :
imageId = int ( getLastImage ( cur ) + 1 )
imageId = int ( getLastImage ( cur ) + 1 )
@ -505,15 +507,13 @@ def create_image(cur, base64Image, date):
newImage = False
newImage = False
if newImage :
if newImage :
decImage = decode_decrypt_image_in_base64 ( base64Image )
hashImage = generate_image_hash ( decImage )
hashImage = generate_image_hash ( decImage )
hloFeatures = extract_hidden_layer_output ( decImage )
hloFeatures = extract_hidden_layer_output ( decImage )
keypoints , descriptors = extract_keypoints ( decImage )
keypoints , descriptors = extract_keypoints ( decImage )
sql = " Insert into market_images(image_id, hash_image, base64_image, " \
sql = " Insert into market_images(image_id, hash_image, base64_image, " \
" resnet50_image, siftkey_image, siftdesc_image, dateinserted_image) " \
" resnet50_image, siftkey_image, siftdesc_image, dateinserted_image) " \
" Values ( %s , %s , %s , %s , %s , %s , %s ) "
" Values ( %s , %s , %s , %s , %s , %s , %s ) "
recset = [ imageId ,
recset = [ imageId ,
@ -556,11 +556,11 @@ def create_database(cur, con):
sql = " create table market_images(image_id integer not null, hash_image character varying(64) not null, base64_image character varying(10000000) not null, " \
sql = " create table market_images(image_id integer not null, hash_image character varying(64) not null, base64_image character varying(10000000) not null, " \
" resnet50_image character varying(1000000) null, siftkey_image character varying(1000000) null, siftdesc_image character varying(1000000) null, " \
" resnet50_image character varying(1000000) null, siftkey_image character varying(1000000) null, siftdesc_image character varying(1000000) null, " \
" dateinserted_item timestamp(6) with time zone not null, " \
" constraint item s_pk primary key (image_id)) "
" dateinserted_image timestamp(6) with time zone not null, " \
" constraint market_image s_pk primary key (image_id)) "
cur . execute ( sql )
cur . execute ( sql )
sql = " create unique index unique_image ON market_images USING btree (hash_image ASC NULLS LAST) "
sql = " create unique index unique_market_ image ON market_images USING btree (hash_image ASC NULLS LAST) "
cur . execute ( sql )
cur . execute ( sql )
sql = " create table marketplaces(market_id integer not null, name_market character varying(255) not null, " \
sql = " create table marketplaces(market_id integer not null, name_market character varying(255) not null, " \