-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed5885d
commit 6ef1ad7
Showing
13 changed files
with
387 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import cv2 | ||
import numpy as np | ||
|
||
|
||
|
||
def recovery(ori_img,attacked_img,outfile_name = './recoveried.png',rate=0.7): | ||
img = cv2.imread(ori_img) | ||
img2 = cv2.imread(attacked_img) | ||
|
||
height = img.shape[0] | ||
width = img.shape[1] | ||
# Initiate SIFT detector | ||
orb = cv2.ORB_create(128) | ||
MIN_MATCH_COUNT=10 | ||
# find the keypoints and descriptors with SIFT | ||
kp1, des1 = orb.detectAndCompute(img,None) | ||
kp2, des2 = orb.detectAndCompute(img2,None) | ||
|
||
FLANN_INDEX_KDTREE = 0 | ||
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5) | ||
search_params = dict(checks = 50) | ||
|
||
flann = cv2.FlannBasedMatcher(index_params, search_params) | ||
|
||
|
||
|
||
des1 = np.float32(des1) | ||
des2 = np.float32(des2) | ||
|
||
matches = flann.knnMatch(des1,des2,k=2) | ||
|
||
# store all the good matches as per Lowe's ratio test. | ||
good = [] | ||
for m,n in matches: | ||
if m.distance < rate*n.distance: | ||
good.append(m) | ||
|
||
if len(good)>MIN_MATCH_COUNT: | ||
src_pts = np.float32([ kp1[m.queryIdx].pt for m in good ]).reshape(-1,1,2) | ||
dst_pts = np.float32([ kp2[m.trainIdx].pt for m in good ]).reshape(-1,1,2) | ||
M, mask = cv2.findHomography( dst_pts,src_pts, cv2.RANSAC,5.0) | ||
out = cv2.warpPerspective(img2, M, (width,height)) #先列后行 | ||
cv2.imwrite(outfile_name,out) | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .BlindWatermark import watermark | ||
from .ncc import NCC | ||
from .ncc import average_ncc | ||
from .psnr import average_psnr | ||
from .psnr import average_psnr | ||
from .tools import recovery |
Binary file modified
BIN
+62 Bytes
(100%)
GUI/BlindWatermark/__pycache__/BlindWatermark.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import cv2 | ||
import numpy as np | ||
from PyQt5.QtCore import pyqtSignal, QThread | ||
|
||
|
||
|
||
class recovery(QThread): | ||
num_of_good=pyqtSignal(int,str) | ||
def __init__(self,ori_img,attacked_img,outfile_name = './recoveried.png',rate=0.7): | ||
QThread.__init__(self) | ||
self.ori_img = ori_img | ||
self.attacked_img = attacked_img | ||
self.outfile_name = outfile_name | ||
self.rate = rate | ||
|
||
def run(self): | ||
img = cv2.imread(self.ori_img) | ||
img2 = cv2.imread(self.attacked_img) | ||
|
||
height = img.shape[0] | ||
width = img.shape[1] | ||
# Initiate SIFT detector | ||
orb = cv2.ORB_create(128) | ||
MIN_MATCH_COUNT=10 | ||
# find the keypoints and descriptors with SIFT | ||
kp1, des1 = orb.detectAndCompute(img,None) | ||
kp2, des2 = orb.detectAndCompute(img2,None) | ||
|
||
FLANN_INDEX_KDTREE = 0 | ||
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5) | ||
search_params = dict(checks = 50) | ||
|
||
flann = cv2.FlannBasedMatcher(index_params, search_params) | ||
|
||
|
||
|
||
des1 = np.float32(des1) | ||
des2 = np.float32(des2) | ||
|
||
matches = flann.knnMatch(des1,des2,k=2) | ||
|
||
# store all the good matches as per Lowe's ratio test. | ||
good = [] | ||
for m,n in matches: | ||
if m.distance < self.rate*n.distance: | ||
good.append(m) | ||
|
||
if len(good)>MIN_MATCH_COUNT: | ||
src_pts = np.float32([ kp1[m.queryIdx].pt for m in good ]).reshape(-1,1,2) | ||
dst_pts = np.float32([ kp2[m.trainIdx].pt for m in good ]).reshape(-1,1,2) | ||
M, mask = cv2.findHomography( dst_pts,src_pts, cv2.RANSAC,5.0) | ||
out = cv2.warpPerspective(img2, M, (width,height)) #先列后行 | ||
cv2.imwrite(self.outfile_name,out) | ||
self.num_of_good.emit(len(good),self.outfile_name) | ||
else : | ||
self.num_of_good.emit(0,'') | ||
|
This file contains 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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.