熊猫:如何通过索引将系列更改为嵌套列表

时间:2016-11-15 19:42:05

标签: python pandas

我的系列看起来像这样:

int main(int argc, char* argv[])
{
   cv::Mat frame(1200, 1920, CV_8UC3, cv::Scalar(0, 50000, 50000));

   cv::VideoWriter* videoWriter = new cv::VideoWriter(
                "C:/videos/desktop.avi", 
                 CV_FOURCC('D','I','V','3'), 
                 5, cv::Size(1920, 1200), true);

   int frameCount = 0;

   while (frameCount < 100)
   {
      videoWriter->write(frame);
      ::Sleep(100);
      frameCount++;
    }

    delete videoWriter;
    return 0;
}

我想把它改成一个基于这样的组的嵌套列表:

int main(int argc, char* argv[])
{
   cv::VideoWriter* videoWriter = new cv::VideoWriter(
                "C:/videos/desktop.avi", 
                 CV_FOURCC('D','I','V','3'), 
                 5, Size(1920, 1200), true);

   int frameCount = 0;

   while (frameCount < 100)
   {
      HWND hDsktopWindow = ::GetDesktopWindow();
      cv::Mat frame = hwnd2mat(hDsktopWindow);
      videoWriter->write(frame);
      ::Sleep(100);
      frameCount++;
   }

   delete videoWriter;
   return 0;
}

cv::Mat hwnd2mat(HWND hwnd)
{
   HDC hwindowDC, hwindowCompatibleDC;
   int height, width, srcheight, srcwidth;
   HBITMAP hbwindow;

   cv::Mat src;
   BITMAPINFOHEADER  bi;

   hwindowDC = GetDC(hwnd);
   hwindowCompatibleDC = CreateCompatibleDC(hwindowDC);

   SetStretchBltMode(hwindowCompatibleDC, COLORONCOLOR);

   RECT windowsize;    // get the height and width of the screen
   GetClientRect(hwnd, &windowsize);
   srcheight = windowsize.bottom;
   srcwidth = windowsize.right;
   height = windowsize.bottom / 1;  //change this to whatever size you want to resize to
   width = windowsize.right / 1;

   src.create(height, width, CV_8UC3);

   // create a bitmap
   hbwindow = CreateCompatibleBitmap(hwindowDC, width, height);
   bi.biSize = sizeof(BITMAPINFOHEADER);   
   bi.biWidth = width;
   bi.biHeight = -height;  //this is the line that makes it draw upside down or not
   bi.biPlanes = 1;
   bi.biBitCount = 32; 
   bi.biCompression = BI_RGB;
   bi.biSizeImage = 0;
   bi.biXPelsPerMeter = 0;
   bi.biYPelsPerMeter = 0;
   bi.biClrUsed = 0;
   bi.biClrImportant = 0;

   // use the previously created device context with the bitmap
   SelectObject(hwindowCompatibleDC, hbwindow);

   // copy from the window device context to the bitmap device context
   StretchBlt(hwindowCompatibleDC, 0, 0, width, height, hwindowDC, 0, 0,srcwidth, srcheight, SRCCOPY); 

   GetDIBits(hwindowCompatibleDC, hbwindow, 0, height, src.data, (BITMAPINFO*)&bi, DIB_RGB_COLORS);

   // avoid memory leak
   DeleteObject(hbwindow); DeleteDC(hwindowCompatibleDC); ReleaseDC(hwnd,hwindowDC);

   return src;
}

有人可以帮忙吗?感谢!!!

1 个答案:

答案 0 :(得分:3)

IIUC:

s.groupby(s.index).apply(list)

s是你的系列