Ejemplo n.º 1
0
        public dynamicstestyesno(
            string test_propositions_filename,
            int image_width, int image_height)
        {
            this.image_width  = image_width;
            this.image_height = image_height;
            test_image        = new byte[image_width * image_height * 3];
            for (int i = image_width * image_height * 3 - 1; i >= 0; i--)
            {
                test_image[i] = 255;
            }
            bmp            = new Bitmap(image_width, image_height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            mouse_position = new List <double>();
            mouse_time     = new List <DateTime>();

            propositions = new List <string> [10];
            rnd          = new Random();
            for (int i = 0; i < 10; i++)
            {
                propositions[i] = new List <string>();
            }

            BitmapArrayConversions.updatebitmap_unsafe(test_image, bmp);
            bmp.Save("test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

            if (File.Exists(test_propositions_filename))
            {
                LoadPropositions(test_propositions_filename, "Mind Hack", propositions);
            }
        }
Ejemplo n.º 2
0
        private void CreateTestImage()
        {
            for (int i = image_width * image_height * 3 - 1; i >= 0; i--)
            {
                test_image[i] = 255;
            }

            BitmapArrayConversions.updatebitmap_unsafe(test_image, bmp);
            bmp.Save("blank.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

            int font_size = 20;

            yesno_y = image_height * 1 / 10;
            radius  = image_height / 12;
            int left_x  = image_width / 10;
            int right_x = image_width - 1 - left_x;

            yes_left = true;
            if (rnd.NextDouble() > 0.5)
            {
                yes_left = false;
            }

            drawing.drawSpot(test_image, image_width, image_height, left_x, yesno_y, radius, 200, 255, 200);
            drawing.drawSpot(test_image, image_width, image_height, right_x, yesno_y, radius, 200, 255, 200);

            if (yes_left)
            {
                yes_x = left_x;
                no_x  = right_x;
            }
            else
            {
                yes_x = right_x;
                no_x  = left_x;
            }
            drawing.AddText(test_image, image_width, image_height, "Yes", "Courier", font_size, 0, 0, 0, yes_x - font_size, yesno_y - font_size);
            drawing.AddText(test_image, image_width, image_height, "No", "Courier", font_size, 0, 0, 0, no_x - font_size, yesno_y - font_size);

            BitmapArrayConversions.updatebitmap_unsafe(test_image, bmp);
            bmp.Save("test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// add some text to the given image
        /// </summary>
        /// <param name="img">colour image into which to insert th text</param>
        /// <param name="img_width">width of the image</param>
        /// <param name="img_height">height of the image</param>
        /// <param name="text">text to be added</param>
        /// <param name="font">font style</param>
        /// <param name="font_size">font size</param>
        /// <param name="r">red</param>
        /// <param name="g">green</param>
        /// <param name="b">blue</param>
        /// <param name="position_x">x coordinate at which to insert the text</param>
        /// <param name="position_y">y coordinate at which to insert the text</param>
        public static void AddText(byte[] img, int img_width, int img_height,
                                   String text,
                                   String font, int font_size,
                                   int r, int g, int b,
                                   float position_x, float position_y)
        {
            Bitmap screen_bmp = new Bitmap(img_width, img_height,
                                           System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            // insert the existing image into the bitmap
            BitmapArrayConversions.updatebitmap_unsafe(img, screen_bmp);

            Font       drawFont  = new Font(font, font_size);
            SolidBrush drawBrush = new SolidBrush(Color.FromArgb(r, g, b));

            Graphics grph = Graphics.FromImage(screen_bmp);

            grph.DrawString(text, drawFont, drawBrush, position_x, position_y);
            grph.Dispose();

            // extract the bitmap data
            BitmapArrayConversions.updatebitmap(screen_bmp, img);
        }
Ejemplo n.º 4
0
        public void ShowAllResults()
        {
            StreamReader oRead     = null;
            bool         filefound = true;

            int bucket_pixels = 5;
            int group_ms      = 60;
            int font_size     = 20;

            yesno_y = image_height * 1 / 10;
            radius  = image_height / 12;
            int left_x  = image_width / 10;
            int right_x = image_width - 1 - left_x;

            for (int i = image_width * image_height * 3 - 1; i >= 0; i--)
            {
                test_image[i] = 255;
            }
            drawing.drawSpot(test_image, image_width, image_height, left_x, yesno_y, radius, 200, 255, 200);
            drawing.drawSpot(test_image, image_width, image_height, right_x, yesno_y, radius, 200, 255, 200);
            drawing.AddText(test_image, image_width, image_height, "Yes", "Courier", font_size, 0, 0, 0, right_x - font_size, yesno_y - font_size);
            drawing.AddText(test_image, image_width, image_height, "No", "Courier", font_size, 0, 0, 0, left_x - font_size, yesno_y - font_size);

            int[,,] average = new int[image_height, 10, 2];
            int histogram_max = 1;

            int[] histogram_no  = new int[image_width];
            int[] histogram_yes = new int[image_width];
            int[,] histogram_decision_time = new int[5, 1000];
            int      max_decision_time_mS       = 100;
            int      decision_time_hist_max     = 1;
            float    average_decision_time      = 0;
            int      average_decision_time_hits = 0;
            DateTime prev_timestamp             = new DateTime(1900, 1, 1);

            byte[] test_image2 = new byte[test_image.Length];
            for (int i = image_width * image_height * 3 - 1; i >= 0; i--)
            {
                test_image2[i] = 255;
            }

            try
            {
                oRead = File.OpenText(results_filename);
            }
            catch
            {
                filefound = false;
            }

            if (filefound)
            {
                while (!oRead.EndOfStream)
                {
                    int  steps    = Convert.ToInt32(oRead.ReadLine());
                    bool yes      = Convert.ToBoolean(oRead.ReadLine());
                    bool yes_left = Convert.ToBoolean(oRead.ReadLine());
                    coherence_index = Convert.ToInt32(oRead.ReadLine());
                    int      prev_x               = 0;
                    int      prev_y               = 0;
                    DateTime start_time           = DateTime.Now;
                    int      decision_time_mS     = 0;
                    float    speed_pixels_per_sec = 0;
                    int      prev_x2              = 9999;
                    int      prev_y2              = 0;

                    for (int t = 0; t < steps; t++)
                    {
                        string   s         = oRead.ReadLine();
                        string[] s2        = s.Split(' ');
                        DateTime timestamp = DateTime.FromBinary(Convert.ToInt64(s2[0]));
                        if (t == 0)
                        {
                            start_time = timestamp;
                        }
                        if (t == steps - 1)
                        {
                            TimeSpan diff    = timestamp.Subtract(start_time);
                            int      time_mS = (int)diff.TotalMilliseconds;
                            if (time_mS / 4 < 1000 / 4)
                            {
                                if (time_mS > max_decision_time_mS)
                                {
                                    max_decision_time_mS = time_mS;
                                }

                                histogram_decision_time[coherence_index / 2, time_mS / 250]++;
                                if (histogram_decision_time[coherence_index / 2, time_mS / 250] > decision_time_hist_max)
                                {
                                    decision_time_hist_max = histogram_decision_time[coherence_index / 2, time_mS / 250];
                                }
                                average_decision_time += (float)time_mS;
                                average_decision_time_hits++;
                            }
                        }
                        int x = Convert.ToInt32(Convert.ToSingle(s2[1]));
                        if (yes_left)
                        {
                            x = image_width - 1 - x;
                        }

                        int y = Convert.ToInt32(Convert.ToSingle(s2[2]));
                        if (t > 0)
                        {
                            int entropy = (5 - Math.Abs(coherence_index - 5)) * 255 / 5;
                            //Console.WriteLine("entropy = " + entropy.ToString());

                            if (coherence_index == 9)
                            {
                                drawing.drawLine(test_image, image_width, image_height, prev_x, prev_y, x, y, entropy, 0, 255 - entropy, 0, false);
                            }
                            if (coherence_index == 5)
                            {
                                drawing.drawLine(test_image2, image_width, image_height, prev_x, prev_y, x, y, entropy, 0, 255 - entropy, 0, false);
                            }

                            int step = 1;
                            if (y < prev_y)
                            {
                                step = -1;
                            }
                            int n = 0;
                            if (y - prev_y != 0)
                            {
                                int yy = prev_y;
                                while (yy != y)
                                {
                                    int xx = prev_x + ((x - prev_x) * n / (Math.Abs(y - prev_y)));
                                    if ((xx > -1) && (xx < image_width) &&
                                        (yy > -1) && (yy < image_height))
                                    {
                                        average[yy, coherence_index, 0] += xx;
                                        average[yy, coherence_index, 1]++;

                                        if (yes)
                                        {
                                            int xx2 = xx / bucket_pixels;
                                            histogram_yes[xx2]++;
                                            if (histogram_yes[xx2] > histogram_max)
                                            {
                                                histogram_max = histogram_yes[xx2];
                                            }
                                        }
                                        else
                                        {
                                            int xx2 = xx / bucket_pixels;
                                            histogram_no[xx2]++;
                                            if (histogram_no[xx2] > histogram_max)
                                            {
                                                histogram_max = histogram_no[xx2];
                                            }
                                        }
                                    }

                                    yy += step;
                                    n++;
                                }
                            }
                        }
                        prev_x = x;
                        prev_y = y;
                    }
                }
                oRead.Close();
            }

            BitmapArrayConversions.updatebitmap_unsafe(test_image, bmp);
            bmp.Save("test_results_low_entropy.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            BitmapArrayConversions.updatebitmap_unsafe(test_image2, bmp);
            bmp.Save("test_results_high_entropy.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

            for (int i = image_width * image_height * 3 - 1; i >= 0; i--)
            {
                test_image[i] = 255;
            }
            drawing.drawSpot(test_image, image_width, image_height, left_x, yesno_y, radius, 200, 255, 200);
            drawing.drawSpot(test_image, image_width, image_height, right_x, yesno_y, radius, 200, 255, 200);
            drawing.AddText(test_image, image_width, image_height, "Yes", "Courier", font_size, 0, 0, 0, right_x - font_size, yesno_y - font_size);
            drawing.AddText(test_image, image_width, image_height, "No", "Courier", font_size, 0, 0, 0, left_x - font_size, yesno_y - font_size);

            drawing.drawLine(test_image, image_width, image_height, image_width / 2, 0, image_width / 2, image_height - 1, 220, 220, 220, 1, false);

            for (int coherence_index = 0; coherence_index < 10; coherence_index++)
            {
                bool labeled = false;
                int  r       = 255 - (255 * coherence_index / 10);
                int  g       = 255 * coherence_index / 10;
                for (int y = 0; y < image_height; y++)
                {
                    if (average[y, coherence_index, 1] > 0)
                    {
                        int x = average[y, coherence_index, 0] / average[y, coherence_index, 1];
                        drawing.drawSpot(test_image, image_width, image_height, x, y, 1, r, g, 0);

                        if ((!labeled) && (y > image_height * 15 / 100))
                        {
                            drawing.AddText(test_image, image_width, image_height, "0." + coherence_index.ToString(), "Courier", 10, 0, 0, 0, x, y + rnd.Next(40) - 20);
                            labeled = true;
                        }
                    }
                }
            }
            BitmapArrayConversions.updatebitmap_unsafe(test_image, bmp);
            bmp.Save("test_results_average.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

            /*
             * for (int i = image_width*image_height*3-1; i >= 0; i--)
             *      test_image[i]=255;
             * drawing.drawLine(test_image, image_width, image_height, image_width/2, 0, image_width/2, image_height-1, 220,220,220,1,false);
             * for (int x = 1; x < image_width/bucket_pixels; x++)
             * {
             *      int prev_y_yes = image_height - 1 - (histogram_yes[x-1]*(image_height*110/100)/histogram_max);
             *      int prev_y_no = image_height - 1 - (histogram_no[x-1]*(image_height*110/100)/histogram_max);
             *      int y_yes = image_height - 1 - (histogram_yes[x]*(image_height*110/100)/histogram_max);
             *      int y_no = image_height - 1 - (histogram_no[x]*(image_height*110/100)/histogram_max);
             *      drawing.drawLine(test_image, image_width, image_height, (x-1)*bucket_pixels, prev_y_yes, x*bucket_pixels, y_yes, 0,255,0,0,false);
             *      drawing.drawLine(test_image, image_width, image_height, (x-1)*bucket_pixels, prev_y_no, x*bucket_pixels, y_no, 255,0,0,0,false);
             * }
             * BitmapArrayConversions.updatebitmap_unsafe(test_image, bmp);
             * bmp.Save("test_results_horizontal.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
             */

            /*
             * for (int i = image_width*image_height*3-1; i >= 0; i--) test_image[i]=255;
             * for (int coherence_index=0; coherence_index<5;coherence_index++)
             * {
             *      int r = 255-(coherence_index*255/5);
             *      int g = coherence_index*255/5;
             *      for (int t = 1; t < max_decision_time_mS/250; t++)
             *      {
             *              int prev_x = (t-1) * image_width / (max_decision_time_mS/250);
             *              int x = t * image_width / (max_decision_time_mS/250);
             *
             *              int prev_y = image_height - 1 - ((histogram_decision_time[coherence_index,t-1]) * image_height / decision_time_hist_max);
             *              int y = image_height - 1 - ((histogram_decision_time[coherence_index,t]) * image_height / decision_time_hist_max);
             *              drawing.drawLine(test_image, image_width, image_height, prev_x, prev_y, x, y, r,g,0,1,false);
             *      }
             * }
             * BitmapArrayConversions.updatebitmap_unsafe(test_image, bmp);
             * bmp.Save("test_results_decision_times.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
             */
        }