- fix width/height confusion, add new pixelate on
authorEric Zavesky <ezavesky@research.att.com>
Mon, 16 Oct 2017 14:45:53 +0000 (09:45 -0500)
committerEric Zavesky <ezavesky@research.att.com>
Mon, 16 Oct 2017 14:45:53 +0000 (09:45 -0500)
multiple faces

README.md
face_privacy_filter/transform_detect.py
face_privacy_filter/transform_region.py
web_demo/images/commercial.jpg [new file with mode: 0644]
web_demo/images/commercial_pixelate.jpg [new file with mode: 0644]

index 9ac8d26..eaaae2c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -51,15 +51,15 @@ composed together for operation.
 ```
 * Dump the `pixelate` model to disk.
 ```
-./bin/run_local.sh -d model_pix -f pixelate
+./bin/run_local.sh -d model_pix -f pixelate -i image.jpg -p predict.csv
 ```
 * Evaluate the `detect` model from disk and a previously produced detect object
 ```
-./bin/run_local.sh -d model_detect -f detect -p output.csv -i web_demo/images/face_DiCaprio.jpg
+./bin/run_local.sh -d model_detect -p output.csv -i web_demo/images/face_DiCaprio.jpg
 ```
 * Example for evaluating the `pixelate` model from disk and a previously produced detect object
 ```
-./bin/run_local.sh -d model_pix -f pixelate -i detect.csv -p output.jpg --csv_input
+./bin/run_local.sh -d model_pix -i detect.csv -p output.jpg --csv_input
 ```
 
 
@@ -80,15 +80,21 @@ and visualize the results of image classification.
 
 * [DiCaprio celebrity face sample](web_demo/images/face_DiCaprio.jpg) [wikimedia source](https://en.wikipedia.org/wiki/Celebrity#/media/File:Leonardo_DiCaprio_visited_Goddard_Saturday_to_discuss_Earth_science_with_Piers_Sellers_(26105091624)_cropped.jpg)
 * [Schwarzenegger celebrity face sample](web_demo/images/face_Schwarzenegger.jpg) [wikimedia source](https://upload.wikimedia.org/wikipedia/commons/thumb/0/0f/A._Schwarzenegger.jpg/220px-A._Schwarzenegger.jpg)
+* [Commercial example](web_demo/images/commercial.jpg) [youtube source](https://www.youtube.com/watch?v=34KfCNapnUg)
+
 
 <table width='100%'>
 <thead>
 <tr><td width='49%'>before</td><td width='49%'>after</td></tr>
 </thead>
 <tbody>
-<tr style='max-height:100px;'>
+<tr >
     <td><img src="web_demo/images/face_DiCaprio.jpg" alt="raw" height="100px;"/></td>
     <td><img src="web_demo/images/face_DiCaprio_pixelate.jpg" alt="pixelate" height="100px;"/></td>
 </tr>
+<tr >
+    <td><img src="web_demo/images/commercial.jpg" alt="raw" height="100px;"/></td>
+    <td><img src="web_demo/images/commercial_pixelate.jpg" alt="pixelate" height="100px;"/></td>
+</tr>
 </tbody>
 </table>
\ No newline at end of file
index 35dc3d4..656db86 100644 (file)
@@ -55,6 +55,7 @@ class FaceDetectTransform(BaseEstimator, ClassifierMixin):
     @staticmethod
     def suppress_image(df):
         keep_col = [FaceDetectTransform.COL_FACE_X, FaceDetectTransform.COL_FACE_Y,
+                    FaceDetectTransform.COL_FACE_W, FaceDetectTransform.COL_FACE_H,
                     FaceDetectTransform.COL_FACE_W, FaceDetectTransform.COL_FACE_H,
                     FaceDetectTransform.COL_REGION_IDX, FaceDetectTransform.COL_IMAGE_IDX]
         blank_cols = [col for col in df.columns if col not in keep_col]
@@ -111,7 +112,7 @@ class FaceDetectTransform(BaseEstimator, ClassifierMixin):
 
             df = pd.DataFrame()  # start with empty DF for this image
             if self.include_image:  # create and append the image if that's requested
-                dict_image = FaceDetectTransform.generate_out_dict(w=img.shape[0], h=img.shape[1], image=image_idx)
+                dict_image = FaceDetectTransform.generate_out_dict(w=img.shape[1], h=img.shape[0], image=image_idx)
                 dict_image[FaceDetectTransform.COL_IMAGE_MIME] = X[FaceDetectTransform.COL_IMAGE_MIME][image_idx]
                 dict_image[FaceDetectTransform.COL_IMAGE_DATA] = X[FaceDetectTransform.COL_IMAGE_DATA][image_idx]
                 df = pd.DataFrame([dict_image])
@@ -154,6 +155,6 @@ class FaceDetectTransform(BaseEstimator, ClassifierMixin):
            https://stackoverflow.com/a/43024993
         """
         from ast import literal_eval
-        if bytearray_string.startswith("b'"):
+        if type(bytearray_string)==str and bytearray_string.startswith("b'"):
             return bytearray(literal_eval(bytearray_string))
         return bytearray_string
index 83bf48f..f106884 100644 (file)
@@ -78,12 +78,12 @@ class RegionTransform(BaseEstimator, ClassifierMixin):
             #print(image_data)
             img = image_data['data']
             for r in image_data['regions']:  # loop through regions
-                x_max = min(r[0]+r[2], img.shape[0])
-                y_max = min(r[1]+r[3], img.shape[1])
+                x_max = min(r[0]+r[2], img.shape[1])
+                y_max = min(r[1]+r[3], img.shape[0])
                 if self.transform_mode=="pixelate":
                     block_size = round(max(img.shape[0], img.shape[2])/15)
-                    img[r[0]:x_max, r[1]:y_max] = \
-                        RegionTransform.pixelate_image(img[r[0]:x_max, r[1]:y_max], block_size)
+                    img[r[1]:y_max, r[0]:x_max] = \
+                        RegionTransform.pixelate_image(img[r[1]:y_max, r[0]:x_max], block_size)
 
             # for now, we hard code to jpg output; TODO: add more encoding output (or try to match source?)
             img_binary = cv2.imencode(".jpg", img)[1].tostring()
@@ -132,6 +132,8 @@ class RegionTransform(BaseEstimator, ClassifierMixin):
     # http://www.jeffreythompson.org/blog/2012/02/18/pixelate-and-posterize-in-processing/
     @staticmethod
     def pixelate_image(img, blockSize):
+        if not img.shape[0] or not img.shape[1]:
+            return img
         ratio = (img.shape[1] / img.shape[0]) if img.shape[0] < img.shape[1] else (img.shape[0] / img.shape[1])
         blockHeight = round(blockSize * ratio)  # so that we cover all image
         for x in range(0, img.shape[0], blockSize):
diff --git a/web_demo/images/commercial.jpg b/web_demo/images/commercial.jpg
new file mode 100644 (file)
index 0000000..3eef94e
Binary files /dev/null and b/web_demo/images/commercial.jpg differ
diff --git a/web_demo/images/commercial_pixelate.jpg b/web_demo/images/commercial_pixelate.jpg
new file mode 100644 (file)
index 0000000..26cf70a
Binary files /dev/null and b/web_demo/images/commercial_pixelate.jpg differ