From 58c279656ca1a0bf48902badf023fa2ace48eaae Mon Sep 17 00:00:00 2001 From: esimov Date: Wed, 13 Mar 2019 07:28:54 +0200 Subject: [PATCH] Fixing index out of range issue --- main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index e52cf1e..0785723 100644 --- a/main.go +++ b/main.go @@ -104,6 +104,10 @@ func main() { log.Fatal("Usage: forensic -in input.jpg -out out.jpg") } + if *blockSize <= 1 { + log.Fatal("ERROR: the block size must be greater then 1.") + } + start := time.Now() input, err := os.Open(*source) @@ -172,7 +176,7 @@ func process(input image.Image, done chan struct{}) float64 { } bar := pb.StartNew(len(blocks)) - bar.Prefix("Generate blocks: ") + bar.Prefix("Generate: ") for _, block := range blocks { // Average RGB value. @@ -275,7 +279,7 @@ func process(input image.Image, done chan struct{}) float64 { simBlocksNum := len(simBlocks) forgedBlocksNum := len(forgedBlocks) - // precision indicated the detection accuracy. + // precision indicates the detection accuracy var precision = 0.0 if forgedBlocksNum > 0 { precision = 100 - (float64(forgedBlocksNum) / (float64(forgedBlocksNum + simBlocksNum)) * 100)